Frage

This is the class text.as3

private function showTextArea():void{
textField = new TextArea();
canvas.addChild(textField); 
        }

This is the code to create the text area,i want to pass the text area to another class(text2.as3).Is it possible?

War es hilfreich?

Lösung

package{
    import fl.controls.*;
    import flash.display.*;
    public class Text1  {
        public var txtA:TextArea;
        public var str:String = "text";             
        public function Text1():void{   }
        public function showText(spr:Sprite):void
        {
            txtA = new TextArea();          
            txtA.text = str;
            spr.addChild(txtA); 
        }
    }
}

and Main class

    package  {
    import flash.display.Sprite;    
    public class Main extends Sprite{
        public function Main():void {
            var spr:Sprite= new Sprite();
            var txt1:Text1 = new Text1();
            txt1.showText(spr);
            addChild(spr);
            trace(txt1.txtA.text);
        }
    }   
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top