Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : CellRenderer with a Loader Component


thronic
6/19/2004 5:08:00 PM
I've sucessfully created a CellRender that will hold a Loader component and
subsequently load an image. The problem is that once the image is loaded,
everytime i roll over and off the image the setValue() function is called and
the image is loaded again. I don't want to have to reload the image all over
again. Is there any way to prevent this? I've attached my code below:




import mx.core.UIComponent;
import mx.controls.Loader
class ImageCell extends UIComponent {
var img:MovieClip;
var url:String;
var listOwner:MovieClip;

var getCellIndex:Function;
var getDataLabel:Function;

function ImageCell() {}

function createChildren(Void):Void {
img = createObject("Loader", "Img", 1, {styleName:this, owner:this});
img.addEventListener("complete", this);
//size();
}
function setValue(str:String, item:Object, sel:Boolean):Void {
//make it visible only if there is a value
img._visible = (item[getDataLabel()] != undefined);

if (item[getDataLabel()]!=undefined){
img.autoload = false;
img.load(item[getDataLabel()]);
img.scaleContent=false;
size();
}
}

function size(Void) : Void
{
img._y = 1
img._width= 32
img._height= 32
}

function complete(){
size();
img._visible = true;
}
}
jbb1973
6/20/2004 5:13:36 PM
You could try only having the code execute when the item changes. Something
like the following
//at top of class
var prevItem;

//within setValue() function
if(prevItem!=item){
//do your loading or whatever
prevItem=item
}
thronic
6/20/2004 11:37:33 PM
Yes. That'll do! I was struck in a rut!

jbb1973
6/21/2004 3:54:08 AM
elrasguno
2/17/2006 1:01:55 AM
:frown;
Ok, I'm using a DataGrid to display song names and they're going to be
downloadable. I've set up a CellRenderer to put _both_ the song name and a
movie clip that will serve as the progress bar when someone is downloading a
song. My question is this: how on god's green earth do I get access to the
objects that were created during the createChildren portion of the class that I
created? Most specifically, I'll end up needing to use a listener to do a
standard download progress bar.

help, please!

kokochka
5/14/2007 4:31:36 PM
Hi,
We have the same problem with you. And the biggest problem is that when we
have more row data and have to scroll in the datagrid,
////////////////////
if(prevItem!=item){
//do your loading or whatever
prevItem=item
}
////////////////////
the "prevItem" part doesn't work, since prevItem takes the last entry visible
before it dissapear and var item is a new value which just come into the pane.
So, all the images previously shown but gone out of the scroll pane HAVE TO BE
reloaded.

Is there any way to just load once at the initialisation and scroll up and
down ?

Please help.


AddThis Social Bookmark Button