Simple Problem - Referencing Objects By Variable Name
I have a simple function that dynamically creates text fields. My text field name is referenced by var thisTextField. Problem is, when i try to do things with my text field, actionscript shoots back an error as such:There is no property with the name 'text'.How am i supposed to apply properties to my object if my objects name is a variable? Code: function showProducts() { var products:Number = 0; var thisTextField:String = "product" + products + "_txt"; for (var itemID in _global.rtsData[_global.rtsPos]["products"]) { this.createTextField(thisTextField,1,25,75,350,50); trace(thisTextField); thisTextField.autoSize = true; product+products+_txt.text = _global.rtsData[_global.rtsPos]["products"][itemID]["products_name"]; products++; } _root.products_mc.gotoAndPlay("fadeIn"); }
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 01-11-2007, 01:37 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
About Referencing Objects And Copying Objects
This is for AS1
hi,
i should know this but i got lost for a bit, can someone make this clear:
i have the following:
code: myobject=new Object()
myobject.var="hello"
getvar=myobject.var
In this case, get var has a reference for myobject.var, or it has just copied de value? mean if i update myobject.var to "good bye" get vatr will be that, too, or will stay as "hello".
If it's just a reference, how can make it a different variable, i mean, assign the value of myobject.var to getvar and loose any relationship between myobject.var and getvar, so if i update one, the other doesn't.
Anyone?
Referencing Objects In A Different SWF
I'm attempting to create my first all-Flash web site. I have a master SWF that will load other SWFs into movie clips or levels.
One of the SWFs I plan to load is a complex menu system. When certain buttons in the menu are selected, I want things to happen in the master SWF file (i.e. other SWFs and text files load). Is there a way to reference objects in the master SWF from the menu SWF? Or is there a way to reference objects in the menu SWF from the master SWF? If both are possible, which way is better?
Referencing Objects
Is there any way to refernce multiple objects with similar names using a loop?
eg button1, button2, button3
code:
for (i=1; i<=3; i++ ) {
button(i)._visible = false;
}
[AS2] Referencing Objects
I have an object called H with a property of mc set equal to hero:
ActionScript Code:
var H:Object = new Object();
H.mc = "hero";
the property mc holds the name of the movie clip the object H deals with
I am trying to retrieve the y coordinate of the movie clip here
I have tried the following but it dont work
ActionScript Code:
function Move(Object) {
trace( this[Object + ".mc"]._y );
}
Move("H");
Referencing Of Array Objects
Hello!
I don't know how many ties I've had this d*mn problem but it never fails - I can't get it to work. Lemme tell you what I am TRYING to do.
I have an array that randomly generates numbers (14). No problem. I call the array alpha cause it controls alpha levels and such (this doesn't matter). I also have a MC on the stage called mc_oval. After each loop (14 of them) - count has one added to it. I want to be able to able to duplicate the mc_oval MC and call each new MC "mc_oval" + count. Each new level is count +1 (so we don't replace level0.
the problem comes when I go to position the dynamic clip. Here is my code:
Code:
n = 14;
count = 0;
alpha = new Array();
while (count<n) {
alpha[count] = randomNum=Math.round(Math.random()*99+1);
//
duplicateMovieClip (_root.mc_oval, "mc_oval_"+count, count+1);
setProperty ("mc_oval_"+count, _x, "25");
count++;
}
Now I have tried this eval() sh*t but it works werid and doesn't fix the problem. I've tried:
eval("mc_oval_" + count);
and
"" + eval('mc_oval_' + count);
I'm lost - please help me!
Referencing Objects Via An Array
hello
i am trying to create a fake email inbox for an eLearning simulation. the brief is thus:
the inbox lists emails. emails are added as the user progresses through the game. for each email, its variables are displayed (from, subject, date received).
i have an array to store the emails in, and an index to keep count:
Code:
// Keeps track of number emails so that they can be put into an array
//and referenced.
emailCount = 0;
// Array to store emails in.
emails = new Array();
i have a constructor to create a new email object:
Code:
function email(newID, newFrom, newSubject, newBody, newDate) {
ID = newID;
emailCount ++;
from = newFrom;
subject = newSubject;
body = newBody;
thisDate = newDate;
read = false;
emails.push(ID);
}
i also have a function to display the emails:
Code:
displayEmails.onPress = function() {
for(i = 0; i < emails.length; i++) {
attachMovie("emailListMember", ["emailListMember" + i], i);
with(["emailListMember" + i]) {
from = _root.emails[i].from;
subject = _root.emails[i].subject;
thisDate = _root.emails[i].thisDate;
ID = _root.emails[i].ID;
_x = 30;
_y = 30 * i + 10;
}
}
}
after creating a couple of email instances, and trying to display them, i find their variables are not set. i think its because the array values do not point to the email instance itself, and merely holds a string.
cheers in advance
Dynamically Referencing Objects
I have generated movie clips with nested textboxes inside inside a dynamic for loop (.createEmptyMovie and .createTextBox).I do this by generating a name with the counter added to it ("mc" + x or 'txtbox" +x) -- Which generates (mc1, mc2,..., txtbox1, txtbox2,...)
I am having troubles trying to reference these individual objects with in the loop to set a value to them (_root.mc[x] and _root.mc[x].txtbox[x]). This attempt doesn't work. If I hard code a number in place of the "[x]" my code runs correctly. I am trying to reference them dynamically because I am reading from a file that could be any length long and I do not want to have to update the fla file any time a new item is added.
Does anyone know how if I could possibly get these objects referenced dynamically or if you need a definite reference to the objects? Thank you
[F8] Referencing Array Of Objects
Ive done this before, but I forget teh notations. I have objcts date1,date2..... save as a movieclip dateBoxes. I cant remember how to referencec them, say, in a for loop.
for (i=0; i==10; i++) {
dateBoxes.["date" + i].text = i;
}
Like that but it has to work lol.
thanks in advance.
Two Objects Referencing Same Array?
I'm working a neural network project and my basic architecture is this:
1. Neurons
2. Neuron Layer (basically an array of neurons)
3. Neural Network (basically an array of Neuron Layers)
When I reference the first Neuron Layer's array.length it gives me the total number of neurons in the network rather than what the number of neurons in the first layer should be. The same thing happens for the second layer and each subsequent layer should there happen to be more. I've added trace statements to the Neuron Layer constructor that tells me a neuron has been added and I've also added a trace statement after the first neuron layer is added and the second neuron layer and I get the correct number of "neuron added" statements before the "first layer added" statement and the correct number for the second layer as well. This pretty much assures me that the actual number of neurons in each layer is correct when the first layer is created but somehow the number of neurons in the first layer and subsequent layers is actually becoming the number of neurons total. The only thing I can figure out is that somehow, the first neuron layer object is referencing the same neuron array member as the second neuron layer object. Is this possibly what is happening?
Here's the code for the Neuron Layer class:
Code:
import Neuron;
class NeuronLayer{
//number on neurons in layer
private var numNeurons:Number;
//array of neurons
private var neurons:Array=new Array();
//number of inputs per neuron
private var numInputsPerNeuron:Number;
//constructor
public function NeuronLayer(numOfNeurons:Number,numOfInputsPerNeuron:Number)
{
numNeurons=numOfNeurons;
numInputsPerNeuron=numOfInputsPerNeuron;
for(var i=0;i<numNeurons;i++)
{
var neuron:Neuron=new Neuron(numInputsPerNeuron);
neurons.push(neuron);
trace("Adding Neuron");
}
}
//function to get the num of neurons in layer
public function getNumNeurons():Number
{
return numNeurons;
}
//function to get the num inputs per neuron
public function getNumInputsPerNeuron():Number
{
return numInputsPerNeuron;
}
//function that returns a copy of the neuron array
public function getNeuronArray():Array
{
var neuronArray:Array=new Array();
neuronArray=neurons.slice();
return neuronArray;
}
}
And here's the code for the Neural Network Class:
Code:
import Neuron;
import NeuronLayer;
class NeuralNetwork{
//number of inputs for network
private var numInputs:Number;
//number of outputs for network
private var numOutputs:Number;
//number of hidden layers
private var numHiddenLayers:Number;
//neurons per hidden layer
private var numNeuronsPerHiddenLayer:Number;
//array of neuron layers
private var neuronLayers:Array=new Array();
//activation response constant
private static var P_SETTING:Number=1;
//constructor, initializes private members for this class and call createNet
//function
public function NeuralNetwork(inputs:Number,
outputs:Number,
hiddenLayers:Number,
neuronsPerHiddenLayer:Number)
{
numInputs=inputs;
numOutputs=outputs;
numHiddenLayers=hiddenLayers;
numNeuronsPerHiddenLayer=neuronsPerHiddenLayer;
createNet();
}
//function that gets the number of inputs
public function getNumInputs():Number
{
return numInputs;
}
//function that get the number of outputs
public function getNumOutputs():Number
{
return numOutputs;
}
//function that gets the number of hidden layers
public function getNumHiddenLayers():Number
{
return numHiddenLayers;
}
//function that gets the number of neurons per hidden layer
public function getNumNeuronsPerHiddenLayer():Number
{
return numNeuronsPerHiddenLayer;
}
//function that returns a copy of the neuron layer array
public function getNeuronLayerArray():Array
{
var neuronLayerArray:Array=new Array();
neuronLayerArray=neuronLayers.slice();
return neuronLayerArray;
}
//builds network from neurons
private function createNet():Void
{
//create layers of network
if(numHiddenLayers>0)
{
//create first hidden layer
var firstHiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numNeuronsPerHiddenLayer);
//push it into the neuron layer array
neuronLayers.push(firstHiddenLayer);
trace("Added first layer");
//create other hidden layers as necessary
for(var i=0; i<numHiddenLayers-1; i++)
{
var hiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numInputs);
neuronLayers.push(hiddenLayer);
trace("Adding Additional layers");
}
//create output layer
var outputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numNeuronsPerHiddenLayer);
neuronLayers.push(outputLayer);
trace("Added output layer");
}
else
{
//create output layer
var defaultOutputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numInputs);
neuronLayers.push(defaultOutputLayer);
}
}
//function that returns all the weights in the network as an array
public function getWeights():Array
{
var weightArray:Array=new Array();
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
weightArray.concat(neuronLayers[i].getNeuronArray()[j].getWeights());
}
}
return weightArray;
}
//function that returns the total number of weights in the network
public function getNumWeights():Number
{
var total:Number=0;
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
total+=neuronLayers[i].getNeuronArray()[j].getWeights().length;
}
}
return total;
}
//replaces old weights with new weights
public function putWeights(weights:Array, newWeights:Array):Void
{
//empties array that's passed
weights=[];
weights=newWeights.slice();
}
//sigmoid response curve applier
public function applySigmoid(activation:Number,responseSetting:Number):Number
{
return 1/(1+Math.pow(Math.E,(-activation/responseSetting)));
}
//calculate outputs from set of inputs
public function update(inputs:Array):Array
{
//stores the resulting outputs from each layer
var outputs:Array=new Array();
var weightCounter:Number=0;
//check for correct number of inputs
if(inputs.length!=numInputs)
{
//just return empty vector if incorrect
return outputs;
}
//for each layer
for(var i=0;i<numHiddenLayers+1; i++)
{
if(i>0)
{
//copies elements into the array
inputs=outputs.slice();
}
//clears array of values
for(var a=outputs.length;a>=0; a++)
{
outputs.pop();
}
weightCounter=0;
//for each neuron sum the inputs*corresponding weights
//throw the total at the sigmoid function to get the output
for(var j=0;j<neuronLayers[i].numNeurons;j++)
{
var netInput:Number=0;
var numOfInputs:Number=neuronLayers[i].neurons[j].numInputs;
//for each weight
for(var k=0; k<numOfInputs-1; k++)
{
//sum of the weights*inputs
netInput+=neuronLayers[i].neurons[j].weights[k]*inputs[weightCounter++];
}
//add in the bias
netInput+=neuronLayers[i].neurons[j].weights[numOfInputs-1]*-1
//we can store the outputs from each layer as we generate them.
//The combined activation is first filtered through the sigmoid
//function
outputs.push(applySigmoid(netInput, P_SETTING));
weightCounter=0;
}
}
return outputs;
}
}
Referencing Objects Within MovieClips
Hey guys, I need some help. I'm new to Flash/Actionscript and what I'm trying to do seems like it should be straight-forward and very common, but for the life of me I can't figure it out.
I've created a MovieClip in the Flash editor called 'MyClip'. As part of this movieclip there is some dynamic text.
I've also defined an ActionScript class for MyClip that inherits from MovieClip. In it there is a member function DisplaySomeText(myText:String). How can I get this function to set the dynamic text that is part of my movieclip?
At first I thought I could just give the dynamic text an instance name (say 'MyTextField') and go:
Code:
public function DisplaySomeText(myText:String)
{
this.MyTextField.text = myText;
but that doesn't work.
How the heck do you do this??
Thanks in advance for any help,
Oliver
Referencing Duplicates From Other Objects...
...is there a way to do it? If so, say I have two movie clips A and B, and I've made duplicates of A. How can I reference each A from:
1. Any of the other A duplicates? and
2. The B movie clip?
What is the scoping syntax for that? I tried to use _root.{the name of A duplicate}.{property} for accessing A from B but it didn't seem to work.
Referencing Objects On Stage
Ok, this is a dumb question but I'm just horribly stuck.
In my script I go toframe 5, and there are several textfields and clips on stage, but I can't reference them from my code. I get an error saying the objects don't exist.
If I move the objects of stage and just move them into place later that works but I'm pretty sure there is a better way to do it.
Any thoughts or links? I've checked around google but I don't know exactly what I should be searching for here.
Referencing Objects On Separate Timelines
If I have a dynamic textbox that exists only on the last frame of a movieclip and I need to set the text for it from the main timeline, how would I reference it? I tried referencing it by going mc.hint_mc.hintText_txt.text = "Bla" but that doesn't work and I realized that could be because the textbox only exists on one frame of the movieclip. Is there a way to do this?
Referencing Objects Created By Functions
Hi, I've been using Actionscript 2 for a while, bit of a newbie with 3 (and objects and classes etc.) though, so I'm just running into small issues from time to time I'm completely confused by. :|
So I have a function, called initMainMenu that includes all the code for creating a menu, which is a list of movie clips inside a container movie clip.
Inside that function I create a movie clip object called mainMenuContainer, and an array called menuList.
Then I create movieclip objects using items in the library, and add them to the menuList array. These are the items in the menu. Then I call a second function from inside this function, called arrangeMenu, which just does a little for in loop to give the menu items a y property, adds EventListeners to them, and adds them as children of the mainMenuContainer. Maybe that's a clumsy way of doing things, but that's not the problem.
The problem is that Flash won't run the second function because when it gets to the part where I say
mainMenuContainer.addChild(array[ i]) - space added to avoid italics tag :P
it says:
"1120: Access of undefined property mainMenuContainer."
So I'm thinking, "Okay, what the hell?"
It wasn't necessary to keep that as a separate function, so I solved this by just putting the contents of the arrangeMenu function inside initMainMenu. But that's a temporary solution to a broader problem, because now I've got the same problem with a third function (the function called by the EventListeners) that I can't just lump inside the first. How come I can't refer to objects created by a function from inside other functions? Is it a problem with the order I'm writing them in, or how they're called? I am confused. :|
Having A Problem Referencing Objects On Stage ?
Hi everybody,
I am having a problem referencing two objects on stage and telling them to swap depths. I have an object called "illustration" on the stage that has two separate layers inside of it. These two layers hold "illustrationText" and "illustrationTextRed". My problem comes when I try to swap the depth of the two child objects (illustrationText, illustrationTextRed).
The code I placed on the timeline:
PHP Code:
illustration.addEventListener(MouseEvent.ROLL_OVER, onIllustrationOver);
illustration.addEventListener(MouseEvent.ROLL_OUT, onIllustrationOut);
function onIllustrationOver(event:MouseEvent):void
{
root.illustration.swapChildren(illustrationText, illustrationTextRed);
}
function onIllustrationOut(event:MouseEvent):void
{
root.illustration.swapChildren(illustrationText, illustrationTextRed);
}
Compiler errors keep getting thrown:
Access of undefined property illustrationText
Access of undefined property illustrationTextRed
Am I going about this the right way?
Thanks for your help!
-Brian
Referencing Display Objects From An Array
Hi
My Psuedo Code:
Code:
myArray = [MC_01, MC_02, MC_03]
for (arrayLength){
myArray[i].addEventListener(MouseDown)
}
Listener(evt) {
stage.addChild(evt.target) //To bring Clicked MC to top of display list
}
Basically what i'm doing is having my array of MC's jumbled on the stage and when I click I want it to come forward. The way I have made objects move to the top previously is using addChild again on it... and it worked fine. With my code i'm getting
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.displayisplayObject.
as I try to addChild again. How do I reference the MC properly and make it jump forward properly? I cna't seem to work it out.
Thanks in advance
Jethro
Referencing Objects Created With A Loop
I know there is simple answer here but Im getting tired so here I am.
I am creating buttons for a menu dynamically based on the amount of items in an array. I can create the buttons and labels for them and even make them access their corresponding page that they link to. My question is for the rollover effect, when I roll over I want the text on the button to shift to the right, but because all the buttons were added in a loop I can only reference the last button created.
I think my question is how do I change the instance name of an object? I though .name did it but that doesn't seem to change the actual reference name of an object.
here is what I have:
Code:
for(i=0; i <= numPages - 1; i++){
var menubut:MovieClip = new menuBut();
menubut.name = "b"+(i + 1);
menubut.y = 10 + i * 20;
menubut.pageTitle.text = pages[i];
menubut.addEventListener(MouseEvent.CLICK, changePage);
menubut.addEventListener(MouseEvent.MOUSE_OVER, overMenu);
menubut.addEventListener(MouseEvent.MOUSE_OUT, offMenu);
menucon.addChild(menubut);
}
function overMenu(event:MouseEvent):void{
temp = event.target.name;
menucon[temp].pageTitle.x += 3;
}
function offMenu(event:MouseEvent):void{
temp = event.target.name;
menucon[temp].pageTitle.x -= 3;
}
pages is the array and numPages is the length of that array. menucon is the mc that all the menu buttons go into.
Referencing Objects By Name Created At Runtime
Referencing objects by name created at runtime, how do you do it?
Ive remember reading that its tough, but can't seem to find the work around.
I have thumbnail objects (with a thumb class) that are created in a loop and added to a thumbholder class, with the name property added (thumb.name, which when traced is thumb0, thumb1, etc). After runtime I want to interact with the thumbs via mouse events in the thumbholder, e.g. when thumb0 is clicked thumb4 is moved to x=60. But trying to reference thumb0 doesnt work and when I reference thumb it will always return the final thumb, e.g. thumb5.
Referencing Dynamically Loaded Clips/objects
I've been playing around with building a tile based game after checking out a couple tutorials.. I've established an overhead level with a moveable character and static objects within that environment. My problem is, that I can't seem to properly reference the character or objects (enemy0-7) within a function of the frame. I've tried a variety of possible references (_root.clip.char, etc..) to no avail.. I've attached the FLA (put the map below). Anyone have any ideas?
Thanks,
Shawn
the map is a text file named map.as located in the same folder as the swf.. map works fine.. Here's what's in map.as:
map = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ];
// startPosition [x,y]
startPos = [9,14];
// enemys startPositions [x,y]
enemys = [[2,1],[18,2],[9,8],[6,15],[12,18],[10,12],[15,15]];
Aligning Variable Sized Objects And Objects Inside Them
Hi,
How do I align a movieclip, which width and height is user-defined, inside another object (this one is static, though). Top-left alignment is easy, x=0 and y=0, but what about center, center left, bottom left, etc? Math(.round) i suppose, but how?
and
I want an object (static) inside the movieclip (user-defined) to stay aligned to, for instance, the top right corner, similiar to the minimize, maximize and close buttons at the top right of your browser..
The height and width data is pre-defined by the user in another file... But that does probably not make any difference...
If anyone could help me with this, I'd appreciate it alot!
Thanks!,
Peter
Referencing A Variable
Hi,
I'm having trouble referencing a variable. I have a movie clip containing another two movie clips and I need to set the width of one of the movie clips equal to the length of a text variable (to create a dynamic shadow) so I'm using this code:
onClipEvent (load) {
this._xscale=../text.length*50;
}
but this doesn't work, how do I move up the heirachy one movie clip before drilling down into it?
Thanks
A Pem Referencing A Variable
The following line in my code works just fine:
k = _root.answer4.substr(1,4)
The problem is, the number "4" is a variable that is generated using the following code:
_parent._name.substr(1, 1)
I can't find a way to use this code in the "k =" line so that it works. I have tried:
k = eval("_root.answer" + _parent._name.substr(1, 1) + ".substr(1,4)")
but of course, "eval" doesn't work the same way in Actionscript as it does in Javascript.
Anybody know how to make this work?
Variable Referencing?
ok i have numerous mc and in each mc it has the same variable so my question is how do i change that variable in each mc the variable is "k" so how would i label that in other words how would i specify in each change in each variable-- and in each mc i want to change the variable to be different in every one
any help is greatly appreciated
Referencing With A Variable
Hey all,
Feel kinda dim for asking this, however...
I have a variable, passed to a function that is the name of the movieclip I want actions performed on. My code is simply:
function changeSub(sect, secName) {
_parent.sect.gotoAndPlay(secName);
}
How do I make it know that 'sect' is a variable, and not the name of the MC? I'm sure it's something simple I'm overlooking.
Cheers,
dreeft.
Referencing With A Variable
Hey all,
Feel kinda dim for asking this, however...
I have a variable, passed to a function that is the name of the movieclip I want actions performed on. My code is simply:
function changeSub(sect, secName) {
_parent.sect.gotoAndPlay(secName);
}
How do I make it know that 'sect' is a variable, and not the name of the MC? I'm sure it's something simple I'm overlooking.
Cheers,
dreeft.
Referencing A Variable
I have a movie with 3 scenes:
1) Intro
2) Main
3) Credits
I am loading variables into the first scene ("Intro")
How do I reference those variables in scene 2 ("Main").
The variable names are:
strVar0,strVar1,strVar2 ... strVar(N)
Referencing Variable In Parent .swf
I'm loading a .swf into a level (200) and I'm trying to set the value of a variable in the parent .swf from the loaded .swf.
I've tried:
parentvar = 21
/arentvar = 21
_root.parentvar = 21
Does anyone know how to do this?
I would really appreciate it.
Using A Variable Within Dot Notation Referencing ?
I've got a variable which is a counter: _root.currentpos
I want to refence a mc with this counter appended to the clip name.
like "myclip"+ "_root.currentpos"._x=77;
how do i go about doing this?
thanks
m
Referencing Variable Names
Referencing variables
Hi I have some code that looks like this.
on (rollOver) {
setProperty("over", _visible, true);
}
on (release) {
// display appropriate fields
setProperty("../button" + n, _visible, false);
location = eval("link" + n);
i = eval("location");
trace(i);
_root.definition = location;
_root.term = linkname;
_root.example = eval("_root.exam");
_root.hint = eval("_root.hint");
}
on (releaseOutside, rollOut) {
setProperty("../button" add n, _visible, true);
setProperty("over", _visible, false);
}
</cite>
</html>
Okay, I want to assign variables to text boxes... This works for the first two types _root.definition _root.term .
THe problem is that when i try and do a simular method that is ussed for obtaining the location variable i.e make location the variable of variable "link" + the instance number "n"
it dosent work for anything else but the location variable.
So..
I want to know how do i find out, what location variable is set to (not the string in the variable the container name of location one) so I can extract the "n" part of the from the "link" part and then assign the n to a variable and add it to the other evauluated strings.
So basically how to i get the container name of a variable???
I am using flash mx, and this code is from a scrooling item list.
Need help quick
Ænertia
Referencing A Variable As An Instance Name
I have a set of buttons numbered 1-10, each with an instance name of b1, b2, b3 etc... depending on which button is pressed I want to move an indicator (which is an underline) to the position of that button to display to the user which page they are on. I have a variable called whichButton that I can get the value of the instance name but am having trouble actually getting the variable to be recognized as an instance name when telling the indicator to move its ._x position...
any thoughts?
function indicate() {
var button = "b";
trace(button+" this is the button prefix");
var whichButton = button+pageNum;
trace(whichButton+" this is the button Instance Name");
subNav.indicator._x = subNav.whichButton._x;
}
//whenever a button is pressed it updates pageNum with the value of that button, so button 3 when pressed pageNum = 3; and so on //
Variable Referencing/Scope
Sorry for the newbie question, but my books are not doing a superb job of explanation...
I have a flash document that has multiple scenes, and I need to have a couple of variables that I can reference and/or change throughout the document. Can anyone tell me the syntax to declare and reference these kinds of variables?
For example in Scene 1, named Login, I have:
var bLoggedIn:Boolean;
....
bLoggedIn = True;
Now, I need to use that variable in an if test in Scene 2, named SavedReports:
if(bLoggedIn == True){
....
}
I have tried the following with a result of undefined:
_root.bLoggedIn
bLoggedIn
_root.Login.bLoggedIn
Thanks a bunch for the help!!!
Referencing A Variable From Within A .as File?
Basically what I've created is a class that when clicked it adds 10 to a given variable:number and updates it accordingly.
I've assigned it via linkage to a simple rectangle on the stage and it updates everything properly with each click.
What I want to do is be able to reference that number elsewhere, such as in a dynamic text field or have it relate to the size of another object.
This is whats inside of the .as file:
Code:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class PointClass extends MovieClip
{
public var energy:Number = 0;
public var points:Number = 0;
public function PointClass()
{
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, pointClick);
}
public function pointClick(event:MouseEvent):void
{
energy = (energy + 10);
points = (points + 10);
}
}
}
But when I transfer:
Code:
trace(energy);
trace(points);
from within the pointClick function in my .as file to the main timeline in flash (which also includes import PlayerRotation; ), I no longer get the updated return and instead receive a message stating that "energy" and "points" are unknown.
Isn't that what a public variable is? Doesn't it have the ability to be referenced from any file its host file is imported to?
How do I go about this?
Referencing MovieClips With Variable
I'm trying to reference a movieClip instance with a counter variable, i.e.
var my_pic:MovieClip = "Pic" + picCount;
I have ten movie clips, with instance names Pic1, Pic2, Pic 3 etc, and
picCount increments from 1 to 10.
No luck so far, as the above code is an illegal mismatch of variable type.
Can this be done? What's the correct syntax?
Variable Referencing Problem
Hi everyone. I can't seem to nail this.
This works......
a=0; //these variables a and b will eventually be set by other components on
the fly.
b=0;
booleanCondition=a||b; //set boolean equation
trace (booleanCondition); //trace shows either a 0 or 1
if (booleanCondition==1){
trace("condition is true")
}
if (booleanCondition==0){
trace("condition is false")
}
Now....what i want to do is instead of explicity stating the boolean
equation in the script, i would like to be able to enter (for convenience)
the boolean via a varable called "booleanCondition" defined in the
parameters panel for my component. I thought this would be easy, but have
not been successful after many hours.
eg
a=0; //these variables a and b will eventually be set by other components on
the fly.
b=0;
trace (booleanCondition); //the output panel shows a||b whereas before it
contained 0 or 1 ....mmmm.
if (booleanCondition==1){
trace("condition is true")
}
if (booleanCondition==0){
trace("condition is false")
}
Note that now this doesn't work, as booleanCondition seems to hold a||b and
not the evaluated answer....
HELP!!!
Any help would be appreciated....it seems i am just not referencing the
variable properly for this situation, but stuffed if i can work it out. I
also have a sample fla (mx 2004) I can send to anyone who would like to have
a go.
Thanks
Adam :)
p.s thanks Rothrock and Trevor for your help the other day...but i don't
think i explained the problem well enough that time.
Variable Referencing Problem...please Help.
Hi all. I posted this message to the general Flash forum yesterday, but
doesn't seem like anyone can help.
Here is my post::::
Hi everyone. I can't seem to nail this.
This works......
a=0; //these variables a and b will eventually be set by other components on
the fly.
b=0;
booleanCondition=a||b; //set boolean equation
trace (booleanCondition); //trace shows either a 0 or 1
if (booleanCondition==1){
trace("condition is true")
}
if (booleanCondition==0){
trace("condition is false")
}
Now....what i want to do is instead of explicity stating the boolean
equation in the script, i would like to be able to enter (for convenience)
the boolean via a varable called "booleanCondition" defined in the
parameters panel for my component. I thought this would be easy, but have
not been successful after many hours.
eg
a=0; //these variables a and b will eventually be set by other components on
the fly.
b=0;
trace (booleanCondition); //the output panel shows a||b whereas before it
contained 0 or 1 ....mmmm.
if (booleanCondition==1){
trace("condition is true")
}
if (booleanCondition==0){
trace("condition is false")
}
Note that now this doesn't work, as booleanCondition seems to hold a||b and
not the evaluated answer....
HELP!!!
Any help would be appreciated....it seems i am just not referencing the
variable properly for this situation, but stuffed if i can work it out. I
also have a sample fla I can send to anyone who would like to have
a go.
Thanks
Adam :)
p.s thanks Rothrock and Trevor for your help the other day...but i don't
think i explained the problem well enough that time.
Variable Referencing Problems
Hi!
I am having big problems referencing variables in Flash! As it turns out, there is no way of referencing a variable(be it any type) that is declared in a timeline parent to the current one... :(
My setup is this: I have a couple of nested MovieClips... I have declared a variable(of type Boolean, let`s say) on the stage. When trying to reference it via stage.bVariable I get an error message saying that I`m trying to reference an undefined proprety, yet it is very well defined!
So, is there a way to do this simple operation??... :(
Thank you in advance!
Variable Referencing (should Be Easy)
Hi,
This is easy but I am having issues.
I have two movieclips, Movieclip1 and Movieclip2.
Movieclip2 has a variable called variable2.
How can I reference variable2 that is in movieclip2 from movieclip1
I thought it would be _root.movieclip2(variable2)
but I am apparently wrong, How do u do it?
Referencing Variable On Another Timeline
Hi gang,
I've got a simple scenario which has been causing some distress and confusion for me. I have a movie clip placed on the stage, which has a variable defined within it. My question is...how can I reference that variable from the _root timeline, without instantiating any on{} statements?
Sounds simple, yes...but I'm unable to do this. I've tried setting the variable in a variety of ways (var, global, Object, etc). No matter how that variable is set, I simply cannot reference from the main timeline, without reading the variable in an on statement block
ex.
trace(_root.mcTest.strTest); // invalid
on(press) {
trace(_root.mcTest.strTest); // correct
}
Thanks in advance to anybody who can enlighten me.
Array Name Referencing With A Variable
Hey all,
fairly simple question (with a long explaination). I have an array, created from the results of another array and it's position in that array. There are actually multiple arrays It can be created from.
Eg.
Array1: clientName1, clientName2, etc.
Array2: clientType1, clientType2, etc.
Second Array: [clientName1,0], [clientName2,1] OR [clientType1,0] etc.
The code for creating the second array is below:
Code:
for (i=0; i<names.length; i++) {
linkArray[i] = [names[i], i];
}
My issue is, I would like to be able to dynamically adjust the array that it is generating from. This would mean changing the bold bit of the code above.
I have tried declaring a variable (type = names+"[i]") and using it in the linkArray declaration, however it will not see this as an array reference, only as a variable.
What I want to know is, how do I reference the name of the original array as a variable so I can update it dynamically?
Array Name Referencing With A Variable
Hi,
I have several arrays that I am using to populate a listbox, the array to be used is dependent on user selection from a comboBox.
I am trying to figure out how to flexibly change the array used to populate the listbox using a variable, when a different comboBox selection is made.
All possible arrays have the same names as possible values from the combobox, so that if 'list1' was selected from combobox, this would call the array named 'list1.' I need to figure out a way to use the selectedArray variable in the for loop to populate the listbox correctly. (see bolded in code)
ActionScript Code:
var selectedArray = evt.target.getValue(); //selected array from comboBox selection. trace("current list contents: " + _global.listcontent); _root.listbox.removeAll();//clears listbox of previous contentfor(var i = 0; i < <b>selectedArray.length</b>; i++){ var item = new Object(); item.label = i + " - " + <b>selectedArray</b>[i]; item.data = i; _root.listbox.addItem(item.label, item.label);}
What I have there is not working, no array is called, but I'm not sure how to make the variable selectedArray reference a specific array simply by name...
I hope I am explaining what I am trying to do well enough. Any help would be greatly appreciated!
Thanks=]
Variable Object Referencing
Hello, I just stumbled across your forums today looking for an answer to my question on Google.
I am in no way very knowledgable with ActionScript, so this might be very simple and I am looking in all of the wrong places... but basically here is my issue:
Instead of accessing an objects attributes like this, _level0.thumbnails.thumbnail0._width = 500;
I want to be able to access it with _level0.thumbnails. (this.id) ._width = 500;
where as (this.id) is a variable that could be equal to "thumbnail0" or "thumbnail99" depending on which object gets clicked. I have everything working to if I hardcode thumbnail0 it works fine, and this.id does get set to whatever thumbnail I click's "thumbnail" + ID
... any help?
Referencing A Variable With A String.
Hey guys,
I have a bunch of variables:
[Embed(source="../assets/illustration.png")] public var illustration:Class;
[Embed(source="../assets/illustration.png")] public var aboutme:Class;
[Embed(source="../assets/illustration.png")] public var web:Class;
[Embed(source="../assets/illustration.png")] public var photography:Class;
And I am trying to call them with a string. So:
var test:Bitmap = new (STRING) as Bitmap;
Obviously the above example doesn't work, I have tried using getDefinitionByName but to no avail, any ideas?
Variable Referencing (should Be Easy)
Hi,
This is easy but I am having issues.
I have two movieclips, Movieclip1 and Movieclip2.
Movieclip2 has a variable called variable2.
How can I reference variable2 that is in movieclip2 from movieclip1
I thought it would be _root.movieclip2(variable2)
but I am apparently wrong, How do u do it?
Referencing Variable On Another Timeline
Hi gang,
I've got a simple scenario which has been causing some distress and confusion for me. I have a movie clip placed on the stage, which has a variable defined within it. My question is...how can I reference that variable from the _root timeline, without instantiating any on{} statements?
Sounds simple, yes...but I'm unable to do this. I've tried setting the variable in a variety of ways (var, global, Object, etc). No matter how that variable is set, I simply cannot reference from the main timeline, without reading the variable in an on statement block
ex.
trace(_root.mcTest.strTest); // invalid
on(press) {
trace(_root.mcTest.strTest); // correct
}
Thanks in advance to anybody who can enlighten me.
Array Name Referencing With A Variable
Hey all,
fairly simple question (with a long explaination). I have an array, created from the results of another array and it's position in that array. There are actually multiple arrays It can be created from.
Eg.
Array1: clientName1, clientName2, etc.
Array2: clientType1, clientType2, etc.
Second Array: [clientName1,0], [clientName2,1] OR [clientType1,0] etc.
The code for creating the second array is below:
Code:
for (i=0; i<names.length; i++) {
linkArray[i] = [names[i], i];
}
My issue is, I would like to be able to dynamically adjust the array that it is generating from. This would mean changing the bold bit of the code above.
I have tried declaring a variable (type = names+"[i]") and using it in the linkArray declaration, however it will not see this as an array reference, only as a variable.
What I want to know is, how do I reference the name of the original array as a variable so I can update it dynamically?
Referencing An Instance Name As A Variable?
I know this might sound like a silly question, but I've been trying to reference an instance name within a function as a variable passed into the function. For example:
Code:
ambient_emissions_monitoring.onRollOver = function(){
linkArrowView('on',this._name);
}
linkArrowView = function(offOrOn,iconPosition){
trace(_root.iconPosition._x);
}
I would like to be able to access all the properties (for example, the x coordinates) for an instance on the stage, but it returns 'undefined'. I'm fairly certain it can be done, I just cannot recall how to do so! Any help would be greatly appreciated.
thanks much!
Jon
Referencing The Variable From External Swf
Guys, I need you help. I want to understand how can I get a modified value of a global variable after it was modified by external swf. Here is what I have: In my main.swf I only have one frame with the following action script that creates a global variable and then loads another swf file that should modify this variable:
Code:
_global.superglobal = "A";
trace("superglobal in main.swf before playlist.swf is loaded: " + superglobal); // should be 'A'
createEmptyMovieClip("playlist_mc", 1);
playlist_mc.loadMovie("playlist.swf");
trace("superglobal in main.swf after playlist.swf is loaded: " + superglobal); // should be 'B' but still 'A' instead
stop();
Then when I load 'playlist.swf' it modifies this global variable, i.e.:
Code:
trace("superglobal in playlist.swf before its modification: " + superglobal);
// change it to 'B':
superglobal = "B";
trace("superglobal in playlist.swf after its modification: " + superglobal);
stop();
Then when I debug all this stuff together, I have the following output:
Code:
superglobal in main.swf before playlist.swf is loaded: A
superglobal in main.swf after playlist.swf is loaded: A
superglobal in playlist.swf before its modification: A
superglobal in playlist.swf after its modification: B
So, the question is why the hell it's still 'A' in main.swf? I mean, how can get the following output, for God's sake:
Code:
superglobal in main.swf before playlist.swf is loaded: A
superglobal in playlist.swf before its modification: A
superglobal in playlist.swf after its modification: B
superglobal in main.swf after playlist.swf is loaded: B
i.e. how can I load a movie, then modify a global variable inside this newly loaded movie and then have this modified value back in my main movie? Thanks in adavance...
Referencing Buttons (simple)
I feel like chump at the moment... you guys are the only ones i can turn to for a quick answer.
All i need to know is how to referrence buttons and assign actions to them. I don't want to put the code directly on the button instance, but rather referrence the button from an actions layer.
Here is what I had.
HTML Code:
DRW.onRelease=function() { trace ("Hello")}
DRW is the instance name of the button.
Eek!
|