Haxe Forum > Differences between haXe and Adode
-
Win john May 14 at 14:44
I have read your link and the document in haxe.org.Last time, I only know AS2.I have read the AS3 code.I realize that haXe and Adobe is the same.Only the addChild (...) and flash.Lib.current.addChild (...) is different.But I can't get the width of the stage.
I tried:var stage=new flash.display.Stage(); var w:Int=Math.round(stage.stageWidth/2); var tf = new flash.text.TextField(); tf.x=w; ................................
And I reviewed the document.But I don't get nothing from stage.Can you tell me more about the differences between haXe and Adobe? -
http://haxe.org/doc/flash/cheatsheet
See the part about:
What is the Stage? What are DisplayObjects?Jan
-
Vjekoslav Ratkajec May 15 at 09:24
You can check out this to see AS3 vs Haxe differences.
Regards,
Vjeko -
Vjekoslav Ratkajec May 15 at 09:25
As to your question about the stage, you get it through Lib.current, don't create instance of it.
-
Win john May 15 at 12:18
I want to put tf in the middle of stage.I have solved the problem:
class Center { static var tf = new flash.text.TextField(); static var st=flash.Lib.current.stage; static function main() { //tf.text = "Hello"; flash.Lib.current.addChild(tf); flash.Lib.current.addEventListener(flash.events.Event.ENTER_FRAME,function(_) Center.onEnterFrame()); } static function onEnterFrame() { tf.x=Math.round(st.stageWidth/2); var t:Int=10; tf.text=Std.string(t); } }
-
Win john May 15 at 12:27
That is how to display a movieclip in the middle of of the stageI have new problem:
Int should be String
For function argument 'string'
Error occurs when I add: Std.string.I know Std.string (value: Dynamic) and String.toString.Int not toString.why? -
I am not seeing a problem?
package; import flash.text.TextField; import flash.display.Sprite; import flash.Lib; import flash.events.Event; class Centre extends Sprite { private var tx: TextField; private var sp: Sprite; private var theta: Float; private static var wid: Float = 100; public static function main() { Lib.current.addChild( new Centre() ); } public function new() { super(); addEventListener( Event.ADDED_TO_STAGE, init ); } public function init( e: Event ) { theta = 0; sp = new Sprite(); addChild( sp ); sp.x = stage.stageWidth/2; sp.y = stage.stageWidth/2; var g = sp.graphics; var c = 0xFF0000; g.beginFill( c, 1 ); g.lineStyle( 0, c, 0 ); g.drawRect( -wid/2, wid/2, wid, wid ); g.endFill(); tx = new TextField(); var s = 10; tx.text = Std.string( s ); // if you want to rotate the textfield you need to embed fonts.. //tx.embedFonts = true; // see haxe.org/byexample/ sp.addChild( tx ); addEventListener( Event.ENTER_FRAME, rotate ); } private static var radius: Float = 25.6/2; public function rotate( e: Event ) { tx.x = 2*radius*Math.cos( theta += Math.PI/60 ) - radius; tx.y = 2*radius*Math.sin( theta ) - radius; } }
-swf Centre.swf -swf-version 9 -main Centre -swf-header 500:500:40:ffffff
-
Win john May 15 at 14:32
I used:
var t:Int=10; tf.text=Std.format("$t"); t=t+Std.parseInt(tf.text); trace(t); //Output: //tf displayed 10; and trace:20
thank you.I'm looking for more problem.I will reply soon if they appear -
package; import flash.display.MovieClip; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField; import flash.Lib; class Center extends MovieClip { var tf:TextField; public function new() { super(); tf = new TextField(); tf.border = true; tf.text = "hello"; addChild(tf); addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } function onAddedToStage(event:Event):Void { removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); stage.addEventListener(Event.RESIZE, onStageResize); onStageResize(null); } function onStageResize(event:Event):Void { tf.x = Math.round(stage.stageWidth/2); } public static function main() { Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE; Lib.current.stage.align = StageAlign.TOP_LEFT; Lib.current.addChild(new Center()); } }
Jan