ActionScript 3.0 :: Can't Access Button With Instance Name
Sep 14, 2009
In my timeline I have a button, with an instance name of view_only_button. On my actions layer, I have code that is attempting to add a listener for a MOUSE_DOWN event. The frame that has the button is the same as where the actionscript is going, but of course it is two different layers. When I try accessing the variable by the code below, I get the error:
Error #1009: Cannot access a property or method of a null object reference.
ActionScript Code:
view_only_button.addEventListener(MouseEvent.MOUSE_DOWN, viewOnlyDownHandler);
function viewOnlyDownHandler(event:MouseEvent):void{
//Code to execute inside of the event call
}
When commenting the addEventListener line out, the error goes away. I am unsure why this would issue an error
i created a button on the stage and made it a movie clip and called it's instance name "play_btn" then i made a document class "main.as" and a second class "play button.as".so what i want to do but can't figure out how is to access the instance name in the play button.as file like this...
public class login_page extends MovieClip { public function login_page() { play_btn.addEventListener(MouseEvent.MOUSE_DOWN, onPlayDown);[code]...
and then i want to call the function in the main.as.. but the general problem is that i want to access the instance name "play_btn" in the "playbutton.as" file...
I created a button (button symbol), inside this button symbol there is a vector shape which will change colours in mouse over and a dynamic text field. i want to use this button symbol in more than one locations in my stage. so i need to change the label of these instances (by changing dynamic text ). but i can't access the dynamic text in as3 using following code,
btnsample.txtbtnlabel.text = "button label"
this code is working fine for a movie clip symbol but not for a button symbol.
i created a button on the stage and made it a movie clip and called it's instance name "play_btn" then i made a document class "main.as" and a second class "play button.as" what i want to do but can't figure out how is to access the instance name in the play button.as file like this...
I placed a movie clip instance inside a button, and I want this movie clip to play when the button is released. I'm using this code on the frame containing the button:
function playMovie(event:MouseEvent) { this.theButton.theMC.gotoAndPlay(3);
I have to admit I pretty much ran away from Flash when AS2 came along and only used it for animation purposes over the last 5 years.So I'm having a major crash course in AS3 in Flash CS3 and I'm not enjoying it one bit. I'm getting maybe 10mins of finished work per hour as I try to figure out the limits and rules of AS3. Quite often it seems that AS3 simply can't do what I want it to. Anyway: Characterchecks.as is the main class and it loads a bunch of XML into four arrays. The file starts like this:[code]If I trace the value of, say, cc._Categories from the main FLA, it's empty. I'm guessing that the next line of AS in the main FLA doesn't wait for the previously called function to complete? (This may tie in to my next problem)My next step is that I want to display various things based on the data in the array. I have another class, Display.as which will hold all the functions to create the items on display. I thought it would be best for these to be a separate object. I wonder if I'm right?
So I declare an instance of Characterchecks in the main FLA and call it cc, and then run the functions to populate the arrays... Now I create an instance of Display and call it cd. How can I get functions in cd to see the values of the variables in cc? And if the main timeline can't tell that the functions aren't finished filling the arrays, how is cd supposed to know?I might be asking dumb questions, or maybe I'm doing things ***-backwards, I don't know. I'd appreciate any help, I really would. This whole thing has me at the end of my tether... being the most technically advanced person in my circle of co-workers and web design friends means I have no-one to explain why things need to be done a certain way or what the best way is.
I am trying to add a LOAD EXTERNAL MOVIE CLIP behaviour to a button sitting in a .FLA called SERVICESMENU. I want to load a .swf titled MULTIMEDIA.SWF into an instance of an empty symbol called PAGE LOADER on a different .FLA called MAIN.FLA.
The problem is when I am in the SERVICEMENU.FLA file, I cannot see the instances that I created in the MAIN.FLA when following the behaviours wizard so I cannot choose the PAGELOADER instance that was created in and resides in the MAIN.FLA file.
if i have a movie clip in my Scene 1 and inside that movie clip is another symbol e.g. a button, how will i reference the instance name of that button in my Scene 1
I have a FLA file and bind it to a class. I need access some instances on the second frame of the FLA file from the class, but I failed because they are not instanced yet.
I have a FLA file and bind it to a class. I need access some instances on the second frame of the FLA file from the class, but I failed because they are not instanced yet.
I am sending the instance name (i.e. String)of the MovieClip to a function.From that function I need to access that same instance of MovieClip using that name.I have a MovieClip Instance name Planet_mc. And I am sending it to function abc()
abc(Planet_mc.name); function abc(s:String):void {
I'm using Flash CS5. I have some instances on my stage declared in the main class and I want to attach some events to them, however at the time of the main class constructor, these are declared as null.
What's the best practice for accessing stage instances? Is there an event listener I could add that will tell me when the stage instance properties have been populated?
Simple example:
public class bleepBloop extends MovieClip { public var productName:TLFTextField; public function bleepBloop() { trace( productName ); // Here it is null } }
However, when I access productName later, it's defined.
I currently pass a reference to my model through the constructor to any class that needs it in my simple mvc pattern, this can get annoying at times when it starts to go deeper.
How do Classes such as LoadMax allow you from anywhere to simple import the class, and do something like addChild(LoaderMax.getContent("bg"));? Replicating this should surely be a good way to have my model work, without the complexity of big frameworks?
for my current project I am starting to work with AS3 and I have written a ClipManager class where I can define an MC like "mainView" during initialization like this:
clipManager:ClipManager = new ClipManager(mainView);
With my clipManager I can now easily load stuff into the mainView etc. The problem is that I want every button throughout the whole thing to access Class Methods of this instance to alter the mainView
So in AS2.0 I would use _global.variableName to create and refer to a variable that was maybe created on the stage and then needed to be referenced to inside of an instance. That doesn't seem to work anymore. Are you expected to not want to do that, or is the code just changed now?
I have a movie clip with a dynamic text box with an instance name inside. The movie clip is linked to a class, but when I try to access that instance name through that class it just returrs null.
In flash, you give the stage a document class (Engine). I'm making the assumption that it creates an instance of this somewhere, but my question is, how the hell do you access this? I have found many places saying to create another instance, this is not what I want
I have a problem with the piece of code that's been annoying me for a week. It should be very simple but all my attempts at a solution somehow seem to get thwarted by an invisible hand that wants me to fail.Here is the scenario: I am trying to create an image strip consisting of image thumbnails. When one mousovers each image it should print its information (say a name) in a textfield.I created an image container class that loads the images through a url request, then an image strip class that receives an array with image names and urls and displays them in a row. So far so good.
However when it comes to showing the info I have no clue how to address which image is being pointed at. I put a variable called imageIndex inside my imageContainer object, then put all the created containers in imageStrip's for-loop inside an array called mgContainerArray. I created a for loop in my fla that goes through this array and assigns all those containers a mouseover event listener. What I'm stumped with is that there is no way I can access the imageIndex variable from my function to tell the code which image is currently being mouseovered. It keeps giving me an error.Here is the code:
I have a class LoadXML which loads and extracts data from an XML file. I am using this data for my Main class by creating a new LoadXML class. I now want to use this data for my other classes but without having to create another new instance of LoadXML. Since global variables dont exist in A3, I tried creating get methods in LoadXML and then returning these values into variables in the desired classes.[code]
What I want to do (and I have high doubts about the possibility of this) is access the creator of a class from within the constructor of that class (without parsing a reference to it).[code]...
The way I've coded it, each instance of a guy class has a mouse even listener on him which listens for a click. When clicked, I find out the tile underneath him, and the surrounding tiles. So far, so good.
When clicked, the guy calls a method in the tile class, like tile.onClick, which tries to say: get this tile, and send it back to a method in the guy class, like moveGuy. Then moveGuy moves the guy to the tile it was told.
Problem:
From the guy class, I call a method in the tile class. To communicate between classes, the tile class method onClick must be static. But if it's static, the method can't refer to "this", because it's a method in the class only, not on each instance of tile. But I need to know which tile was clicked, and send that reference to the guy so he knows where to go.
How do you access a method from outside its class so that the method can refer to "this" instance? OR, how do I find out which tile was clicked without needing any code on each tile instance? OR... how else can this problem be solved?
can anybody tall me how to access mc instance of externally loaded swf? in my as3 file i am trying to stop the animation of externally loaded swf. for that i have loaded the swf into mc sau current mc and i am trying to stop the swf by
currentmc.ballmc.stop();
where ballmc is the mc animation of the externally loaded swf.
- click a guy to select him - click an adjacent tile - move selected guy to clicked tile
The way I've coded it, each instance of a guy class has a mouse even listener on him which listens for a click. When clicked, I find out the tile underneath him, and the surrounding tiles. So far, so good.
When clicked, the guy calls a method in the tile class, like tile.onClick, which tries to say: get this tile, and send it back to a method in the guy class, like moveGuy. Then moveGuy moves the guy to the tile it was told.
Problem: From the guy class, I call a method in the tile class. To communicate between classes, the tile class method onClick must be static. But if it's static, the method can't refer to "this", because it's a method in the class only, not on each instance of tile. But I need to know which tile was clicked, and send that reference to the guy so he knows where to go.
How do you access a method from outside its class so that the method can refer to "this" instance? OR, how do I find out which tile was clicked without needing any code on each tile instance? OR... how else can this problem be solved?
Is this problem what getters & setters are for? I don't really understand how to use them yet.