Oops, seems like I am asking too much question in this forum.... hehe..

So now in the first frame, I put (using the GUI tools) a textfield in flash CS4 and give it an instance name "Status". What I want to do is to update this status from other classes like:

public class Activity extends Sprite {
  public function DoIt() {
     /* do something */
     if(stage!=null) stage.Status.text = "done";
}
}

my problem is that "Status" cannot be accessed. Question: are objects created by the GUI automatically "private"? or what have I done wrong?

Now in the first frame of the fla i add some AS3

var activity:Acitvity = new Activity();
stage.addChild(activity); // makes activity.stage != null
trace(Status.root) // mainTimeLine, so the mainTimeLine is not in DisplayList, not under stage
trace(Status.parent) // mainTimeLine
stage.addChild(Status)// place it on stage, hope activity can access it
trace(Status.root) // stage
trace(Status.parent) // stage

Question: activity still cannot access stage. so what is the difference between mainTimeLine and stage?

Oops, seems like I am asking too much question in this forum.... hehe..

So now in the first frame, I put (using the GUI tools) a textfield in flash CS4 and give it an instance name "Status". What I want to do is to update this status from other classes like:

public class Activity extends Sprite {
  public function DoIt() {
     /* do something */
     if(stage!=null) stage.Status.text = "done";
}
}

my problem is that "Status" cannot be accessed. Question: are objects created by the GUI automatically "private"? or what have I done wrong?

Now in the first frame of the fla i add some AS3

var activity:Acitvity = new Activity();
stage.addChild(activity); // makes activity.stage != null
trace(Status.root) // mainTimeLine, so the mainTimeLine is not in DisplayList, not under stage
trace(Status.parent) // mainTimeLine
stage.addChild(Status)// place it on stage, hope activity can access it
trace(Status.root) // stage
trace(Status.parent) // stage

Question: activity still cannot access stage. so what is the difference between mainTimeLine and stage?

I could be wrong, but I believe that the stage is only accessible from the main class in your app. I've not used CS4 before, but I have found this problem when coding AS3 projects in Flashdevelop.

Consider this pointless random example, this is a Flashdevelop example!

We have a simple class called Thing which just contains a single property called thingSize, which we are trying to set to the value of stage.stageHeight/4:

package 
{
	
	/**
	 * ...
	 * @author Jason Trunks
	 */
	public class Thing
	{
		private var thingSize:Number;
		public function Thing()
		{
			size = stage.stageHeight/4;
		}
	}
	
}

And in our main class, we have a simple property called mainSize, which we'll set to the value of stage.stageHeight, and an instance of the Thing class.

package 
{
	import flash.display.Sprite;
	import Thing;
	
	/**
	 * ...
	 * @author Jason Trunks
	 */
	public class Main extends Sprite
	{
		private var mainSize:Number;
		private var thing:Thing;
		public function Main()
		{
			mainSize = stage.stageHeight; // this will work mainSize will get assigned the value of stage.stageHeight
			thing = new Thing(); // but the creation of our thing object will fail! in fact, the Thing class won't even compile..
		}
	}
	
}

In this example, the Main class will compile fine, up until the part where the Thing class is instantiated....When the compiler tries to compile the code for the Thing class we'll get the following error:
Error: Access of undefined property stage.

Only the main class in your app can can access the stage object.

I think the only way of doing it would be to create an event dispatcher in your Activity class and then set up a listener in your main class to listen for messages from the dispatcher in Activity. Then use an event handler to pass text into your Status class.

Jas.

Only the main class in your app can can access the stage object.

I think the only way of doing it would be to create an event dispatcher in your Activity class and then set up a listener in your main class to listen for messages from the dispatcher in Activity. Then use an event handler to pass text into your Status class.

That is very right i think. I struggled with it for sometime already, i realised this problem does not just happen to the stage instance (of Stage).

basically, the calling class must know the existence of the object being accessed at compile time. Which turned out to be quite... logical and obvious.

In this current problem, Status is non existent during compile time because the Activity class is in its own .as file, and no other definition of Stage has Status in it. Unless we are able to create a new class:

public class MyStage extends Stage {
      var Status:TextField;
}

and "export" the stage as MyStage like how symbols are being exported.

This whole thing makes sense in OOP point of view, but the events model doesn't feel like a sound way to do things....

btw, is the events model asynchronous?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.