Actionscript, set objects invisible -
this script when click object, opens small book page flip effect.
i'm done want when click in button desapears , go seeing original object. not working because deleting 1 of pages! tried doing array didnt work either , im not arrays too. can help?
import fl.transitions.tween; import fl.transitions.easing.*; import fl.transitions.tweenevent; import flash.display.sprite; import flash.display.loader; var cont : displayobject; var cont2 : displayobject; var imgloader : loader; //loads pages (var i:int=0; i<=4; i++){ imgloader = new loader(); imgloader.contentloaderinfo.addeventlistener(event.init, onloadjpeg); imgloader.load(new urlrequest(""+i+".png")); } var imgloader2 : loader; //loads button imgloader2 = new loader(); imgloader2.contentloaderinfo.addeventlistener(event.init, onloadsketch); imgloader2.load(new urlrequest("voltaatrassketchbook.png")); function onloadjpeg (e : event) : void { cont = e.target.loader; cont.x =250; cont.y =50; cont.width = (445-100)/2; cont.height = (604-100)/2; addchild(cont); cont.addeventlistener(mouseevent.mouse_up, flippage); } function onloadsketch (e : event) : void { cont2 = e.target.loader; cont2.x =450; cont2.y =300; cont2.width = 181/2; cont2.height = 127/2; addchild(cont2); cont2.addeventlistener(mouseevent.mouse_up, volta); } function flippage(e:mouseevent):void{ setchildindex(displayobject(e.currenttarget), this.numchildren - 1); if (e.currenttarget.rotationy == 0) { var mytween:tween = new tween(e.currenttarget, "rotationy", regular.easeinout,0, 180, 1, true); } if (e.currenttarget.rotationy == 180) { var mytween:tween = new tween(e.currenttarget, "rotationy", regular.easeinout, 180, 0, 1, true); } } //function go function volta (e: mouseevent): void { gotoandstop(1); cont.visible=false; cont2.visible=false; }
option 1
you right use array. put @ top of code, before start loading pages:
var pages:array = [];
then put final line inside onloadjpeg()
pages.push(cont);
that add each image array when loaded.
then in volta()
can loop through array , make each image invisible
for(var i:int = 0; < pages.length; i++) { displayobject(pages[i]).visible = false; }
option 2
another approach add images container sprite , have make container sprite invisible.
add top of code before load pages :
var pages:sprite = new sprite(); addchild(pages);
then in onloadjpeg()
add cont child of container
pages.addchild(cont);
then in volta()
:
pages.visible = false;
if use approach, don't forget call setchildindex() on container inside of flippage()
:
pages.setchildindex(displayobject(e.currenttarget), this.numchildren - 1);
Comments
Post a Comment