-
Stage from within class
Hi, i have textfield myTxt on stage, and i have Room.as class file.
Actionscript Code:
package { public class Room {
public function Room() { // constructor code myTxt.text = "yo!"; }
} }
I need to access objects on stage from within class.
Thank you.
-
PHP Code:
addEventListener (Event.ADDED_TO_STAGE, onAdded, false, 0, true);
private function onAdded (e:Event) { trace (stage); }
-
5Five555, this code will not work in this situation.
First, the class that Gugis created is not a DisplayObject, since it doesn't extend any of the display object classes, so it can never be aaded to stage.
Second, he didn't ask how to access stage. He wanted to access objects on stage, which were, most probably, created in FLash IDE.
To access them you need to add an instance name to each object, then, pass stage as a constructor to your class, and then use getChildByName() method.
It's one of several methods to do this, but I think it's the simples one. Give it a try.
-
Stage TextField from Class
AscessFromClassAS3.as
Actionscript Code:
package {
public class AscessFromClassAS3 { public var Txt:String; public function AscessFromClassAS3(myTxt:String):void { Txt=myTxt; } public function get access():String{ return Txt; } public function set access(txtVal:String):void { Txt = txtVal; } }
}
Main TimeLine Code of AscessFromClassAS3.fla which will be in the same directory.
Actionscript Code:
var setTxt:AscessFromClassAS3 = new AscessFromClassAS3("Default Label : ");
setTxt.access += "Hello "; setTxt.access +="Flash Class !"; var split:String=":"; var arr=[]; arr=(setTxt.access.split(this["split"])) //myText.htmlText="<b>"+setTxt.access+"</b>"; myText.htmlText=arr[0]+split+"<font color='#BF1E6F'><b>"+arr[1]+"</b></font>";
Obviously the TextField will be on your Stage with an Instance Name myText
Think You are Looking similar to this.
Regards
marlopax
Last edited by marlopax; 03-04-2011 at 02:11 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|