How to load image on a custom GridItem

5 views
Skip to first unread message

Copperjohn

unread,
Aug 12, 2010, 5:42:44 PM8/12/10
to bumpslide
Hi All,

I cannot understand how to load an image in my custom made GridItem.

I made a custom class coping GridItem so it estend Button and
implements IGridItem.

For testing I'm using a dataprovider for GridLayout like this:

myDataProvider = [
{img:"img01.jpg", txt:"skermo52", sfondo:"sfondo01.jpg",
link:"index/nav/home"}];

I have also tryed to look at the ThumbnailItem.as class but there's no
documentation and I don't understand...

Also how is it possible to load the griditems gradualy ?

Thankyou!!!
CopperJohn

tkdave

unread,
Aug 12, 2010, 5:58:11 PM8/12/10
to bumpslide
Are you having trouble with loading the image or accessing the data.
The data is passed to the grid item in the gridItemData property.
Inside the drawGridItem method, you could put something like
myImage.load( gridItemData.img )

Then be sure to unload in the clearGridItem method.

The key thing to remember is that item renders get recycled and
reused. gridItemData property is set to a useful value when it's
used, and it's set to null when it's not. If you implement your
rendering in the draw method directly, be sure to check for null
values of gridItemData and unload things as needed.

Look around the code that's in the examples folder, too. This one is
a useful demonstration of using GridLayout to do scrolling. This is
the demo I created before I made the Grid component. (Try to ignore
the missing images and security warnings. I know it needs an update.)
http://library.bumpslide.com/examples/gridlayout/ScrollTest.as

-dk

Copperjohn

unread,
Aug 12, 2010, 6:51:52 PM8/12/10
to bumpslide
Hi,

For testing i did

inside drawGridItem()

var myImage:Image;
myImage.load(gridItemData.img);

but flash says cannot acces property or method of a null object :-(


on the other side I'm tring to use GridLayout inside a GAIA project
where I have already loader
the images as assets but I cannot figured out how to use them from
GridItem

Thanks for your help...
CopperJohn

On 12 Ago, 23:58, tkdave <tkd...@gmail.com> wrote:
> Are you having trouble with loading the image or accessing the data.
> The data is passed to the grid item in the gridItemData property.
> Inside the drawGridItem method, you could put something like
> myImage.load( gridItemData.img )
>
> Then be sure to unload in the clearGridItem method.
>
> The key thing to remember is that item renders get recycled and
> reused.  gridItemData property is set to a useful value when it's
> used, and it's set to null when it's not.  If you implement your
> rendering in the draw method directly, be sure to check for null
> values of gridItemData and unload things as needed.
>
> Look around the code that's in the examples folder, too.  This one is
> a useful demonstration of using GridLayout to do scrolling.  This is
> the demo I created before I made the Grid component.  (Try to ignore
> the missing images and security warnings.  I know it needs an update.)http://library.bumpslide.com/examples/gridlayout/ScrollTest.as

David Knape

unread,
Aug 12, 2010, 7:15:07 PM8/12/10
to bump...@googlegroups.com
The null error is what I warned about in my last post.  gridItemData should not be null inside the drawGridItem method (I think), but I guess you need to check to make sure gridItemData is not null before you access any of the properties. Debug your swf for more info.  I can't really help you there.

In general, I would create the image in the addChildren method, and then load or unload content based on whether or not you have gridItemData.

For loaded bitmaps, try image.attach( bitmap );

You may also want to check out the updated version of this class which is found here:

There is a new property called 'source' which is designed to be used from mxml, but is just as handy in AS3.  It works like the flex ImageLoader source property in that the value can be a display object such as a bitmap, a url string, or a class reference.

-dk

--
David Knape
Programmer / Consultant


On Thu, Aug 12, 2010 at 4:10 PM, David Knape <da...@bumpslide.com> wrote:
The null error is what I warned about in my last post.  

I would create the image in the addChildren method, and then check to make sure gridItemData is not null before you access any of the properties.

For loaded bitmaps, try image.attach( bitmap );

You may also want to check out the updated version of this class which is found here:

There is a new property called 'source' which is designed to be used from mxml, but is just as handy in AS3.  It works like the flex ImageLoader source property in that the value can be a display object such as a bitmap, a url, or even a class reference.

-dk

--
David Knape
Programmer / Consultant



--
--
Bumpslide Mailing List
http://groups.google.com/group/bumpslide

To post to this group, send email to bump...@googlegroups.com
To unsubscribe from this group, send email to
bumpslide+...@googlegroups.com


Reply all
Reply to author
Forward
0 new messages