haXe Forum > swf doesn' loop Event.Enter_Frame
-
Xeyth Sep 01 at 09:02
Hello,
i'm really new to Haxe. Simple Problem: My swf doesn't loop... Here is my code:import flash.display.MovieClip; import flash.events.Event; import flash.Lib; import flash.text.TextField; import flash.text.TextFieldAutoSize; import haxe.Timer; class Test extends MovieClip { var tf:TextField; public function new() { super(); tf = new TextField(); tf.text = "hello"; Lib.current.addChild(this); addChild(tf); stage.addEventListener(Event.ENTER_FRAME, dostuff()); } private function dostuff():Dynamic { tf.text = " "+ Timer.stamp(); } static function main() { Lib.current.addChild(new Test()); } }
I just get one output and then it stop, so Enter_Frame never is thrown again... :(
please help me^^Greets Xeyth
-
Ali Jaya Meilio Sep 01 at 10:06
i will try to fix your code
import flash.display.MovieClip; import flash.events.Event; import flash.Lib; import flash.text.TextField; import flash.text.TextFieldAutoSize; import haxe.Timer; class Test extends MovieClip { var tf:TextField; public function new() { super(); tf = new TextField(); tf.text = "hello"; addChild(tf); stage.addEventListener(Event.ENTER_FRAME, dostuff); } private function dostuff(e:Event):Void { tf.text = " "+ Timer.stamp(); } static function main() { Lib.current.addChild(new Test()); } }
okay... when you want to make an instance of Test Class and you want to add it to the root, you must not add 'this' again in the constructor
and then... in the addEventListener you must pass a function dostuff not the return value of dostuff
and you may need to add e:Event as a argument to the function and the function doesn't return anything (Void)
-
Xeyth Sep 01 at 10:44
oh man, thx to you - now i see my misstakes - and now it works wonderful... :)
Sometimes I can't see the forest for the trees.Thank you a lot
Xeyth