actionscript 3 - Turn image array images to buttons AS3 -
i'm creating app search function. display images loading array one's match search criteria. images loaded library. want able click on image though button. once click want goto frame 3 , change variable integer image clicked on can display information photo in frame 3. can using event listener say
imagesarray[i].addeventlistener(mouseevent.click, imageclick); function imageclick(event:mouseevent):void { gotoandstop(3); current = i; }
or similar, thanks
yes, won't easy. first, bitmaps not process events, can't assign listener directly bitmap object. next, there no "i" available in such construction, have determine "i" yourself. that, parse event.target
property, object that's been clicked. wrap each bitmap
object separate sprite
object, assign listeners these sprites, parse event.target
relevant object reference out of it, grab index via indexof()
call, , assign global current
variable.
for (i=0;i<imagearray.length;i++) { var sp:sprite=new sprite(); sp.addchild(imagearray[i]); // position "sp" correctly here addchild(sp); sp.addeventlistener(mouseevent.click, imageclick); } function imageclick(e:event):void { var content=e.target.getchildat(0); // object wrapped var i:int=imagearray.indexof(content); if (i==-1) return; // ow, out of array current=i; gotoandstop(3); }
Comments
Post a Comment