actionscript 3 - How to pass a variable into an Event.COMPLETE function? -


i running loop pull thumbs containing movieclip xml list. want have thumb's parent movieclip fade in after done loading, can't figure out how reference parent once it's loaded.

my code(which doesn't work way want it):

var vsthumb:articlebox; var currentarticlex:number = 0; var articlelinkurl:string; var articleimageurl:string; var articletext:string; var vsthumbloader:loader; var next_x:number; next_x = 9; var thumbalphatween:tween; var articlevsthumb:array = new array();  function loadarticleheadlines():void {     (var i:int = 0; < egarticlexml.articlelist.articleitem.length(); i++)     {         vsthumb = new articlebox();         vsthumb.alpha = 0;         vsthumbloader = new loader();         vsthumbloader.load(new urlrequest(egarticlexml.articlelist.articleitem[i].articlethumbnail));         articlelistcontainter.addchild(vsthumb);         vsthumb.articleimage.addchild(vsthumbloader);         vsthumb.articletitle.text = egarticlexml.articlelist.articleitem[i].articletitle;         titleautosize(vsthumb.articletitle);         vsthumb.x = next_x;         next_x += 260;         articlevsthumb[i] = vsthumb;         vsthumbloader.contentloaderinfo.addeventlistener(event.complete, showbox);         vsthumb.clickbtn.buttonmode = true;     }     function showbox(event:event):void      {         thumbalphatween = new tween(articlevsthumb[i],"alpha",none.easenone,0,1,.25,true);     } } 

so how refer loader's parent can fade in whole movieclip? can pass variable showbox function?

  1. don't use nested functions. tend make things more complicated.
  2. i have end value (articleitem.length()-1) in of event handlers create, because scope outer function, loadarticleheadlines (it increase 1 on every iteration). that's why code doesn't work.
  3. the event fired on loaderinfo of loader, can find loader's parent using event.target.loader.parent:

    function loadarticleheadlines() : void {     (var i:int = 0; < egarticlexml.articlelist.articleitem.length(); i++)     {         vsthumb = new articlebox();         vsthumb.alpha = 0;         vsthumbloader = new loader();         vsthumbloader.load(new urlrequest(egarticlexml.articlelist.articleitem[i].articlethumbnail));         articlelistcontainter.addchild(vsthumb);         vsthumb.articleimage.addchild(vsthumbloader);         vsthumb.articletitle.text = egarticlexml.articlelist.articleitem[i].articletitle;         titleautosize(vsthumb.articletitle);         vsthumb.x = next_x;         next_x += 260;         articlevsthumb[i] = vsthumb;         vsthumbloader.contentloaderinfo.addeventlistener(event.complete, showbox);         vsthumb.clickbtn.buttonmode = true;     } }   function showbox(event:event):void  {     thumbalphatween = new tween(event.target.loader.parent,"alpha",none.easenone,0,1,.25,true); } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -