ActionScript 3.0 :: Using This[] To Reference A Variable - Not Working ?
May 2, 2010
I'm writing a function which can take the names of different variables and use them to do some calculations. Long story short, I want to be able to call the function like this:
It probably seems like a really roundabout way to pass the variable through its name rather than just passing the variable itself. This is related to me using XML to get the variable names, so they come in as strings. Just bear with me here.
Inside the function, I want to be able to do something like this:
which should then trace the variable's value. Unfortunately, I just get an 'undefined'. How do I use 'this[]' to get the value of the variable from a string corresponding to the variable's name?
I'm writing a function which can take the names of different variables and use them to do some calculations. Long story short, I want to be able to call the function like this:
function caseConditionEvaluator( nameOfVariable:String )
It probably seems like a really roundabout way to pass the variable through its name rather than just passing the variable itself. This is related to me using XML to get the variable names, so they come in as strings. Just bear with me here.
Inside the function, I want to be able to do something like this:
trace( this[nameOfVariable] )
which should then trace the variable's value. Unfortunately, I just get an 'undefined'. How do I use 'this[]' to get the value of the variable from a string corresponding to the variable's name?
In my document class, I am instantiating a class like this:
cues = new CuePoints(); cues.addEventListener(CuePoints.CUE_POINTS_CLASS_ADDED, setCuePoints); addChild(cues);
[Code]....
If I try to reference a MC that sits on the stage called videoPlayer_main like so: stage.videoPlayer_main I get the following error: 1119: Access of possibly undefined property videoPlayer_main through a reference with static type flash.display:Stage.
I want to be able to reference the text of a text box within an MCThe MC is called "box1", the text field is called "field1"...I have many MCs (all with field1 in them)... box1, box2, box3 etc etcObviously I can set the text to being something by saying...box1.field1.text = "set_this_text"However, I'm using a variable to come up with the "box1" bit. (Using an array and a loop to figure out which box I want to update based on where the user clicked). So, let's say I have a variable... and I want to say..boxClickedon = box1 //will be defined by userSo I don't know in advance about box1... I can only access it through "boxClickedin" variable, but
boxClickedin.field1.text = "set_this_text" or [boxClickedin].field1.text = "set_this_text"
i have a function that read a variable from a text file, yet i can only read the variable from within the function. How could i create a global variable or such that i can then read from outside of the function.
Code: var Make:LoadVars = new LoadVars(); Make.onLoad = function() { VARIABLE = Make.textVariable;
The scene is a number of movie clips, all already added to the stage (i.e. not dynamically) and when one is clicked, I need to call a property of that clip. [code]...
Primitive types in AS3 pass by value instead of reference. Is there a way to override that behavior and pass by reference for certain variables? [code]...
Is there, uh, a way to use the value of a string to reference a variable name?
I'm trying to dynamically assign XML node names and attributes using a string value, I tried something like this:
Code: var sItem:String = "book"; // to be dynamically assigned for (var i:uint; i < _xml.book.length(); i++) { aList.push(_xml.(this[sItem])[i].@title);
If I wanted to change the 'x' of a object, and a variable contained a the object's name, how would I change the 'x' by using the variable.Without variable:
Code: myObject.x = 123; With variable maybe?:[code]....
I desperately hoping someone can shed light on my problem. I am trying to reference a movieclip with a variable. I've done it before but in loops reading from xmlobjects but cannot get it to work in the most simplist way....??ar i = 0;_root.movie[i]._visible=0;
I am unable to view the majority of the downloadable standalone ActionScript 3.0 Language Reference.To replicate:
1) Download the file from [URL] ndalone.zip.
2) Expand the zip, open the resulting folder and open the index.html document in your web browser.
3) Pick any filter link you desire from the choices on this page. Notice that the package and class filters in the header continuously display "Retrieving Data from Server..."
4) Click on the Classes link in the header at the top.
Result: The class list displays only momentarily, then completely hides.
It would be great if there was a way to completely circumvent the filters. There appear to be several missing linked elements in the download, such as en_US/shared/ahpods/AHPod.js.
I'm setting up a class of public static vars that are to be BitmapData.
The problem I'm having is I can't seem to reference the vars dynamically in an array, making it impossible to give them values without some serious procdedural style coding.
Should I assume it's because my array is a private var and placing references to public static vars is illegal? Is somebody gonna call the flash police on me?
I'm creating a dynamic movieclip and the name/instance name is stored in a variable. How can I reference the instance if its stored in a variable?This is what I'm using and it doesnt seem to work (for obvious reasons). I know in php that you do this "blah blah" . $variable.
In AS2 I used to be able to reference a movie clip using a variable like this: Code: var target = nameofmovieclip; I've been looking for an answer on how to do the same thing AS3 but with no luck. I'm trying to create a dynamic homing missle, but unfortunately everything I've tried just generates errors.