ActionScript 3.0 :: Cannot Get Stage From Constructor Method?
Jul 2, 2011
I'm making a kind of image showcase, what has a fluid width and height, depending on browser window dimensions. Everything is okay, I have other kind of issue: in constructor function in this gallery class I can't use stage property, I have to get it from main class. Why Flash treats me this way and how I can avoid this currentStage variable?
Main code:
package dev {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.MovieClip;
[Code] .....
I have a class. I can call the constructor (initialize the class), and the constructor can then call a function/method inside it's own class (so I know it works), but when I try to call the same function/method myself from the instance of the class I just initialized, I get an error.
overloaded constructor method is there in flash? Iam trying the following code but it is giving error like this "A class must have only one constructor."
Code:
function Login(userName:String, userPassword:String) { this.userName = userName; this.userPassword = userPassword;
Some constructor methods I've seen have the return type :void, even though they can't actually return any values anyway. If it's not required, is there a standard/best practice for that?
I just posted a message asking how to call a method from the constructor which has the parameters e: Event. I mistakenly ticked that post as answered when in reality it isnt. I was told I could add = null in the parameter of the function to make it work, like this:
For a project i am needed to move a vast range of movieclips over time on the stage.I thought to write a class to tackle it. my little class experience tells me you can't acces the stage in the constructor. well great, just add an eventlistener for the ADDED_TO_STAGE. I wonder how to pass the stage.stageWidth to a custom class as an optional parameter.[code]
I have encountered a problem when I need to load a third-party flash in to my flash. The flash is written in an erroneous way, it access stage in the main class constructor. I know that a display object can not access to stage property until it is added to stage, and certainly can not access to stage in its main class constructor. I observe 2 cases: - If the flash run STANDALONE, it run well: I don't know why stage is assign before its constructor - If the flash is LOADED by my flash, it yield null reference exception as expected In the second case, if the third-party class remain unchanged, is there a workaround that load flash?
I have a Sprite in my library that is linked to a class (lets call it SomeClass), and i put on stage in Flash, and name the instance someClass. In my Main.as i then write: var myClass:SomeClass = this.someClass; SomeClass.as has a constructor with the same name as the class, however it require an argument. How do I pass that to the class when I made an instance of it directly in Flash by dragging it to the stage? (instead of the usual ... = new SomeClass(arg); )
I tried something like this: myClass.SomeClass(arg); But that gives me this error: 1061: Call to a possibly undefined method SomeClass through a reference with static type SomeClass.
when to use this in a classes?is there any specific rule?is it wrong to use this when you want to just access the stage that way?or is it better to pass the reference to the stage in the class constructor?
I've read a lot of different articles and discussions about the null object reference that occurs when a loaded swf tries to access the stage before it has been added to the display list.
And I'm wondering, "Is there seriously no way to handle this issue without modifying the SWF being loaded?" Even with Flex or otherwise?
Is it possible to pass constructor arguments to instance objects which I place on the stage? Are the instantiations of instance objects centralized somewhere as with .NET WinForms so I can just edit the xxx = new CustomRecangle() constructor?
public class CustomRectangle extends MovieClip { public function CustomRectangle(width:int, height:int) { this.width = width; this.height = height; } }
my movie is linked to an external class called game, and in the game cosntructor I am trying to access instances on my stage. I have tried MovieClip(root).instancename, root.instancename and even tried adding an event listener to listen when the movie is done loading because I thought maybe it was because the instances on the stage weren't created before the constructor is ran. This is the main class, shouldn't it be easy?
There is a library component represented by Class A. But constructor of this class requires some parameters. When the component needs to be added dynamically, it's fine because of code :
var abc:A = new A(param1,param2)
But what if my movieclip is already present on the stage. I notice it gives out error, that the parameters are null.
Is their any way to insert constructor parameters for movieclips already on stage.
I have an object on my stage, called obj.I also have a class called "Physics" which contains a bunch of methods for physics, such as inertia, gravity, and bouncing off walls. In order to do some of these,I need access to the stage.stageWidth and stageHeight properties.My code is as follows:
public function wallBounce(obj) { this.stageRef = stageRef[code]...
This is supposed to check if the object's x value is greater than the stageWidth or less than 0. When I run this code it says:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I am a semi-newbie programmer who is completely self-taught and have no clue what is causing this. I spent a bit googling it, and I think it has something to do with scopes,.
I just began learning AS3. I'm simply trying to play an FLV video. How do you attach the video object to the main stage? I tried but it said that "stage" was undefined.
Is there a way to make an static method act over an object of its class that is already on the stage, without using the keyword "this"? I mean, like "generic object of this class: do what I'm telling you to do, wathever your instance name".My goal is to create an method that get called by any object of this class, based on the changing on the value of an external variable, but since I cannot use the "this" keyword to reffer to each instance, I could not figure out a solution.
I'm having some trouble implementing a "virtual" camera for use in game development with Flash CS4 ActionScript 3.0.Basically, what I'm trying to accomplish is to have a camera that moves about the main stage so that my character can traverse the level which is much larger in size than the stage itself.I've been using Sham Bhangal's virtual camera script, and when I implemented it by sticking the code into the first frame of a movie clip, it worked great!
From there, I moved the code into a document class that i could instantiate and then drop onto the stage as a child.Finally, I wanted to have a main "builder" document class that would be added to the main stage as a child, and within THIS class I wanted an instance of the virtual camera. This is where I hit some obstacles.how to properly instantiate the virtual camera within the builder class which is then added to the main stage. I have a Stage reference that is being passed to the main builder, but I don't know where to go from here. To what do I add the virtual camera to as a child? To the Stage reference in the main builder class? To the main builder class itself?The main issue is that when I export my movie with the virtual camera added as a child to the Stage reference within the main builder class, it complains that I'm not allowed to access certain values.
Code: Error: Error #2071: The Stage class does not implement this property or method. at Error$/throwError() at flash.display::Stage/set x()
This happens when I try to access parent.x from within the virtual camera class. I assume this fails because "parent" from this perspective is the main builder class, but using the Stage reference produces this same error.I am, of course, willing to provide more detail if something I've written is confusing, and I will gladly provide a detailed fix for those seeking to use a similar solution in the future.
So I've been trying to move the stage's X and Y position and keep on getting this error:
Code: Error: Error #2071: The Stage class does not implement this property or method. at Error$/throwError() at flash.display::Stage/set y() at Main/scroll()
As for why I'm trying to move the stage, I have a movieclip which moves according to keyboard input and i want the stage/Background to always center on him.
I am using the draw() method of the BitmapData to encode a jpeg of part of the image. Now this should be easy enough given the object I want to draw to the bitmap is on the stage at design time so I know its location and dimetions exactly! Heres the code I have in place.
Code: var myBitmapSource:BitmapData = new BitmapData ( street.width, street.height, false, 0x333333); myBitmapSource.draw(street, null, null, null, new Rectangle( 96, 5, 571, 450 ), true );
I know for a FACT that no part of the street clip I am drawing out is in negative space, and it's registration is (0,0). However, it cuts off A lot of the top of my image. y=5 in the above rectangle is where I need the top to be, but it cuts the top off of the image... even if I change it to 0, it has no effect.
I'm tryng to make a public static method call another method, but Flash throws error 1180, sayng that the method called by the static method is undefined.
i have a fortran method which creates random numbers. i want to convert this method to a flash method . I want to get numbers from this method and use them in the delay method of flash.
the fortran method is the folowing
real znew1 , zold1 ,a,m,z1,p,TIME1 a= 16807. m=2147483647 B=2