ActionScript 3.0 :: Document Class To Set Stage Layout?
Jul 17, 2009
I am attempting to understand the document class. I have the following code in my current document class in an attempt to set up my stage.I did regarding classes and linking them directly to Library assets, but just as I told him-- I am throwing my pride to the side to try and understand and breaking down to ask the dumb questions.here's the code:
Why would this throw up the error: "1046: Type was not found or was not a compile-time constant: Event." referencing the line in the code: "function setStage ( e:Event = null )"?
How to access a display object on the stage in a class which is not a document class?
I am looking for a solution that doesn't involve passing the stage as a parameter to the class.
One solution i always come across is using "TopLevel.as". Is it a good method because as far as I have heard using global variables is not recommended because it might cause some problems while working on big projects.
I'm being really dumb today and I know this should be simple.....How do i access the stage from a class which isn't the Document Class? For instance, I want to create a tween which takes in the parameters of the stage's width? So I've written.....
ActionScript Code: var myTweenX:Tween = new Tween(this, "x", Regular.easeOut, this.x, stage.stageWidth, 60, true);
How do i access the stage from a class which isn't the Document Class? For instance, I want to create a tween which takes in the parameters of the stage's width?[code]
In my document class named Engine, the stage variable is for some reason null:
package game { import flash.display.MovieClip;
[Code]....
This was working fine up until now. I just recently added two dynamic text fields into a symbol, and all of a sudden the stage is null. I really don't see the connection.
I have a main document class with another class instanciated (mouse follower.as) within it. I want the mouse follower class to access a stage instance. How is this done?
I have a Document Class called Main.as. I tested that it works using a simple trace statement and that outputs fine. I instantiated a Button control and tried to add it to the stage but I keep getting the error thrown below. The code for Main.as is simple and at the end of this thread. I tried all different ways to add the Button to the stage but couldn't figure it out.[code]...
Just tried using cs5 on my new macbook and I have a tlf text object on the stage with an instance name of mText. I tried to access (mText.text = "test") it like this and got a null object reference. I tried to trace the stage from my document class and it was null when the tlftextbox was on the stage but i could trace stage correctly when I deleted the textbox. [code]...
I keep on getting "cannot access property of a null object" errors. With the debugger I pinpointed my issue at the line where I write stage.stageWidth.So somehow the stage is null. This is within my Document class which is linked with the .fla. The strange part is that I haven't had this problem until just recently.
I have drawn buttons on my stage. They all set to export for as3. I then made a class for buttons
package{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.system.fscommand; public class Buttons extends MovieClip{ public function Buttons(){ [Code] .....
And then I put in my document class ; import Buttons; nothing happens and no errors...
I m trying to access stage.width property but sometimes it trace 650 and 720 but i see my flash file dimension is 500x400, I need to align objects on stage..
I have a "box_mc" movieclip on the root of my stage and I need to select it from within my Document Class. I thought Stage.getChildByName("box_mc") would work, but it just returns null.
I'm trying to manipulate (in this particular case add eventListeners) objects (in this case some MovieClips) on the stage from a class that isn't the document class.
1120: Access of undefined property trans.
Now I know that it's probably a scope thing and I probably can't access stage objects directly from a non document class (as I'm doing in the code below) but I can't figure out how to access them properly.
Anyway, here's the deal:
I've got 3 dynamic text fields (called "NL", "FR" and "EN") on my stage in a movieclip called "trans". I'm trying to add eventlisteners in a second class to make them do something when clicked on.
I can access the targetObj instance inside the document class, but when I try to access it in another .as class,get this error: Access of undefined property targetObj.
I am trying to add a keyboard event listener to the stage, to detect when a user clicks the left or right arrow keys. But this listener is called from inside a class file which is imported into the document class, therefore I think it doesn't know what "stage" refers to. How do I solve this?
How do you access the stage from a function in a document class file? I tried a fairly simple: ActionScript Code: var main:MovieClip = new MovieClip(); addChild(main) var _stage:Stage = main.stage; trace(_stage); The result was null.
I have a document class that is connected to a swf but for some reason I can't access the stage/root property. I can access all instance names that are on stage but trying to access stage will return "null". What's up?
Is there a way to get an instance reference to the document class to call a method of it from the stage's timeline?I see that here's a possible solution: using a singletonOther solution I though of is using stage.getChildAt( 0 ) but it's not very nice.Is there an 'official' instance reference? because the document class is obviously instantiated at startup, but is that instance accessible in any way without having to use a custom solution like the ones mentioned?
I'm trying to reference objects on the stage in the current frame from a document class in Actionscript 3 in Flash CS3. In this example, I'm trying to get at a dynamic text field with the instance name "question_txt", but there are also buttons and other things I'll need to get at to put event listeners on and such.
I have "Automatically Declare Stage Instances" checked in the publish settings, so the references should be there -- in fact, if I try to declare them in the class, I get errors about a conflict with the name -- but when I try to reference these objects (in any of several ways I've now tried!) I always get Null.
I have created a game in flash, and due to the nature of the game, I have many movieclips placed on the stage manually in Flash CS4. They are not programmatically added as children to the stage, and so I am having difficulty getting access to them in the document class. So far the only method I have been able to use is to do stage.addChild(active_area); (for example), but there are many movie clips, all very differently named, so this method seems incorrect.I've discovered that my MovieClips are not children of the stage, but in fact MainTimeline, as when I for loop through stage.getChildAt(i);, only one child, root1, is traced out. How can I access movieclips that were placed on the stage in the timeline from the document class, without having to manually add them as children to the stage? So it looks like my problem wasn't that I couldn't access the MovieClips, it was that I wasn't modifying the MovieClips' values, so I wasn't registering any change in them.
Here is the code after I fixed it: function manage_cursor(e:Event):void { prevX=currX;
TypeError: Error #1009: Cannot access a property or method of a null object reference. at QuizApp/createStatusBox() at QuizApp()
That's the error message I get when it tries to play. What I have is an swf that loads another when its done, the new swf is blank but has a document class to an AS file. It seems the problem lies when a function is not properly being added to the stage.
The function is added like this.. Code: package{ public class QuizApp extends Sprite{ public function QuizApp(){ createButtons(); private function createButtons() { if (this.stage == null) { trace("STAGE IS NULL!!!"); } var yPosition:Number; addEventListener(Event.ADDED_TO_STAGE, addedToStage); ...
I'm trying to access a text input that I've already placed on the stage (inside a movie clip) but with no luck.I've defined an instance name for this dynamic text field which is currentUserCount.I've got something like this set up in the document class actionscript file: