actionscript 3 - AS3 - Multiple addEventListener(KeyboardEvent) - Same Key but different Action -
i hope, english enough, understand explanation , "problem"!
endgoal
to navigate through presentation single key, different action ...
- switch between movieclips
- gotoandplay inside movieclip
status
i started build presentation animatecc presentation template,
which ...
maintimeline
as3 actions navigation , movieclip called "slides_mc"
// events stage.addeventlistener(keyboardevent.key_down, fl_changeslide); function fl_changeslide(event:keyboardevent):void { if(event.keycode == 37) // left { fl_prevslide(); } else if (event.keycode == 39) // right { fl_nextslide(); } } // end events // functions , logic function fl_prevslide():void { if(slides_mc.currentframe > 1) { slides_mc.gotoandstop(slides_mc.currentframe-1); } } function fl_nextslide():void { if(slides_mc.currentframe < slides_mc.totalframes) { slides_mc.gotoandstop(slides_mc.currentframe+1); } } slides_mc.gotoandstop(1); // end functions , logic stop();
movieclip slides_mc
inside slides_mc, have multiple movieclips (01, 02, 03,...) on timeline filled content.
a few movieclips splitted inside stop-commands, navigate same keypress!
build overview
maintimeline -> actions -> movieclip (slides_mc) slides_mc -> multiple movieclips (01, 02, 03) movieclips (inside) -> singlestop on endframe ... stop(); //on keypress (next slide) or -> multiplestops ... stop(),.... stop(),.... stop(); //on same keypress (next frame)
problem
jumping between movieclips works should, don't know, do, inside movieclip, action called, same keypress, this
stop(); addeventlistener(keyboardevent.key_down, moveforward); function moveforward(event:keyboardevent):void { if(event.keycode == 39) { gotoandplay (nextframe); } }
i thought, simple implement, more read, more questions got ;(
important!
it has be, same key, because use handpresenter 2 buttons (forward, backward)!
solutions think off
- "overrule" stage.eventlistener on specific frames
- exception on maintimeline/actions (if necessary each movieclip)
- remove / add eventlistener (stage.removeeventlistener(keyboardevent.key_down, fl_changeslide); ... failed, not finding connection fl_changeslide)
so, there "simple" ;) way, working, or easier, split movieclip in more movieclips , happy script have!?
thank in advance!
edit / progress 1
thanks trying ... yes, sounds simple, since i'm no coder, it's trial & error me.
for now, tried adding mainscript:
stage.addeventlistener("firstofframes", callbackfirst); function callbackfirst (event:event):void { trace("first"); stage.removeeventlistener(keyboardevent.key_down, fl_changeslide); stage.addeventlistener(keyboardevent.key_down, moveforward); } stage.addeventlistener("lastofframes", callbacklast); function callbacklast (event:event):void { trace("last"); stage.removeeventlistener(keyboardevent.key_down, moveforward); stage.addeventlistener(keyboardevent.key_down, fl_changeslide); }
and inside movieclips on first frame:
dispatchevent(new event("firstofframes"));
and on last frame:
dispatchevent(new event("lastofframes"));
i'm on right way? ;)
edit / start cratch 1
thank sooo badfeelingaboutthis, that's more (& code needed :)) expected! no way this, trial & error!
but looks like, wrong - it's acting have stop(); in every single frame.
started testfile scratch what have done:
create 2 .as files (slide.as , navigationevent.as) , copy & paste code in it
create new *.fla in same folder
on maintimeline, copy & paste keyboard definitions under actions , create movieclip called slides_mc
inside mc slides_mc, create few other mcs (01, 02, 03) filled few frames, without code (no stop();)
in 1 mc, set few stops on frames ... mc set
stage.dispatchevent(new navigationevent(true)); //pass false back, true (or nothing) forwards
in maintimeline
at last, edit symbolproperties (for slide_mc , mcs 01, 02, 03), check "export actionscript", define classname every single mc , enter slide base class (confirmed ok through testoption)
try run (without given errors) in test environment of animate itself, export direct *.swf , export (win & mac)projector, same result -> in every mc (with or without content), every keypress move 1 frame (forward & backward)
are there tips, can give me, may have forgot or done wrong?
ps: since post getting longer , longer, better delete "beginning of post", or doesn't matter?
i'd you're on right path point 3.
you have 2 handlers same event perform conflicting actions. have turn on off while other active. cannot remove eventlistener inside clips, because have no reference handler function, have on main timeline.
on main timeline remove listener once triggers , moves slides_mc next slide. register listener control current slide. once you're @ end of slide, remove it's listener , notify (custom event) main timeline you're done can re-register main 1 , navigate next slide ... simple enough right?
Comments
Post a Comment