actionscript 3 - AS3 Dispatch event not working -
actionscript 3 - AS3 Dispatch event not working -
i'm confused here. code work flawlessly , went , tried , won't work. can't seem figure out when , i'm starting frustrated result. don't seem errors handed me.
i got 2 files gameindex , 1 external swf level imported on top of gameindex. want move somewhere else on timeline when event called of calling event isn't working.
my code in level such:
private function enterframehandler(event:event):void { updateposition(); updaterotation(); scorebox.text=string(score); var t:number = math.random(); if(t>0.98) { addasteroid(); } (var a:int = 0;a<allast.length;a++) { if (contains(allast[a])) { (var b:int = 0;b<allbullets.length;b++) { if (allbullets[b].hittestobject(allast[a])) { //removechild(allbullet[b]); if (contains(allast[a])) { removechild(allast[a]); } //score score+=5; if (score==20) { dispatchevent(new event("next_level")); } } if (allast[a].hittestobject(_player)) { //removechild(allbullet[b]); trace("hitplayer"); endgame(); } } allast[a].y += 2; } } }//function
now in game index have fallowing code:
import flash.events.event; addeventlistener("next_level", movetointro); function movetointro(e:event){ trace("it working");}
why don't me movetointro function work?
you can seek ( working 100% ) :
package { import flash.display.movieclip; public class game extends movieclip { import flash.events.* private var score:number private static const event_name:string = 'my_event_name' private static const min_score_to_go:number = 20 public function game() { score = 0 addeventlistener(event_name, goto_next_level) } public function score_up(){ score ++ verify_score() } public function score_down(){ score -- verify_score() } private function goto_next_level(e:event){ trace('ok, can go next level') removeeventlistener(event_name, goto_next_level) } private function verify_score(){ trace('score : '+score) if(score == min_score_to_go){ dispatchevent(new event(event_name)) } } } }
actionscript-3 flash dispatchevent
Comments
Post a Comment