Dynamic Variable Names, Set() And Eval() As2 To As3
hello
i've been trying to rewrite this code (it's from flash 8 tutorial) in as3. the problems started with phrasing xml file. here's what i did so far.
Code:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("menu_nav.xml"));
var ID:Array = new Array;
var DisplayName:Array = new Array;
var LinkType:Array = new Array;
var LinkValue:Array = new Array;
var topMenuNum = 0;
function loadXML(e:Event):void
{
var xml:XML = new XML(e.target.data);
trace ("the number of total children is... " + xml.children().length());
var i = 0;
while ( i < xml.children().length()) {
ID.push(xml.children()[i].attributes()[0]);
DisplayName.push(xml.children()[i].attributes()[1]);
LinkType.push(xml.children()[i].attributes()[2]);
LinkValue.push(xml.children()[i].attributes()[3]);
if (ID[i] == "TM") {
topMenuNum = topMenuNum +1;
}
i = i +1;
}
trace ("the total number of top menu items is... " + topMenuNum);
}
now i have some serious problems with this part (it should be before i=i+1). it's to keep track of how many submenu items there will be.
Code:
set ("submenu_Finish_" + ID[i] , i);
if ( eval(".submenu_Start_" + ID[i]) == undefined )
{
set ("submenu_Start_" + ID[i] , i);
Total_subs = Total_subs + 1;
}
set ("Total_Items_in_Submenu_" + ID[i] , eval( "submenu_Finish_" + ID[i]) - eval( "submenu_Start_" + ID[i]) + 1);
there was _global in front of every variable. i removed it coz i dont think it would affect the code at this point
KirupaForum > Flash > ActionScript 3.0
Posted on: 02-27-2008, 08:46 AM
View Complete Forum Thread with Replies
Sponsored Links:
Dynamic Variable Names, Set() And Eval() As2 To As3
hello
i've been trying to rewrite this code (it's from flash 8 tutorial) in as3. the problems started with phrasing xml file. here's what i did so far.
Code:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("menu_nav.xml"));
var ID:Array = new Array;
var DisplayName:Array = new Array;
var LinkType:Array = new Array;
var LinkValue:Array = new Array;
var topMenuNum = 0;
function loadXML(e:Event):void
{
var xml:XML = new XML(e.target.data);
trace ("the number of total children is... " + xml.children().length());
var i = 0;
while ( i < xml.children().length()) {
ID.push(xml.children()[i].attributes()[0]);
DisplayName.push(xml.children()[i].attributes()[1]);
LinkType.push(xml.children()[i].attributes()[2]);
LinkValue.push(xml.children()[i].attributes()[3]);
if (ID[i] == "TM") {
topMenuNum = topMenuNum +1;
}
i = i +1;
}
trace ("the total number of top menu items is... " + topMenuNum);
}
now i have some serious problems with this part (it should be before i=i+1). it's to keep track of how many submenu items there will be.
Code:
set ("submenu_Finish_" + ID[i] , i);
if ( eval(".submenu_Start_" + ID[i]) == undefined )
{
set ("submenu_Start_" + ID[i] , i);
Total_subs = Total_subs + 1;
}
set ("Total_Items_in_Submenu_" + ID[i] , eval( "submenu_Finish_" + ID[i]) - eval( "submenu_Start_" + ID[i]) + 1);
there was _global in front of every variable. i removed it coz i dont think it would affect the code at this point
View Replies !
View Related
Dynamic Variable Names
Hello,
I can't remmeber for the life of me how to create dynamic variable names.
I have an if statement that I want the second part to be dynamic
if (eval(_root.button_1._droptarget) == _root.drop_1)
-----------------------------
So somewhere I set variables
var i = 2
var b = 3
and
if (eval(_root.button_1._droptarget) == _root.drop_1)
becomes:
if (eval(_root.button_1._droptarget) == _root.drop_i)
The 1 at the end is now variable as per the i in the second one.
Any thoughts?
Thanks.....Rob
View Replies !
View Related
Dynamic Variable Names?
for (i=0; i<=numLots; i++) {
currentLot = "_root.vozi.L"+i;
if (("L"+i) == "sold") {
tellTarget (currentLot) {
gotoAndStop(2);
}
}
}
See what I am doing with this line:
if (("L"+i) == "sold") {
I need the loop to go through L1....L72 and check the value of all. All variable values are being passed in from an external file - so I think an array is out of the question. How do I dynamically update the variable name?
View Replies !
View Related
Dynamic Variable Names
how in god's name do I concantenate a variable name from a string and an array index. Here's what I've been trying (this is actionscript, not PHP)...
PHP Code:
var dragNames=new Array(5);
dragNames[0]="Drag1";
dragNames[1]="Drag2";
dragNames[2]="Drag3";
dragNames[3]="Drag4";
dragNames[4]="Drag5";
var targetNames=new Array(5);
targetNames[0]="Target1";
targetNames[1]="Target2";
targetNames[2]="Target3";
targetNames[3]="Target4";
targetNames[4]="Target5";
var i=0;
var thename="";
for(i=0;i<dragNames.length;i++){
var (eval("dragName" + i)) = dragNames[i];
}
for(i=0;i<targetNames.length;i++){
var (eval("targetName" + i)) = targetNames[i];
}
I'm trying to end up with a bunch of variables named "dragName1, dragName2,...etc.
I've tried every variation on the above that I can think of and nothing works. This is soooo easy to do in PHP, but not in ECMA script. Please help!
View Replies !
View Related
Dynamic Variable Names?
ready to shoot myself in the face..... this should be simple...
why does this not work??
I'm trying to write a function to control several different movie clips on the stage ... there is a movie on the stage called 'prv_vancouver' that should play when moused over, but for some reason the 'province.play();' is seeing 'province' as a string and not an instance name... ! arrghh help!
function mouseout(prov) {
var province = ("prv_" + prov);
province.play();
}
btn_vancouver.addEventListener(MouseEvent.MOUSE_OU T,
function button(){
mouseout('vancouver');
}
);
View Replies !
View Related
Dynamic Variable Names?
If you can create a pseudo-variable name on the fly like this (for instance):
ActionScript Code:
n=1;
_root["myVar_"+n] = "hello";
trace(myVar_n); // returns "hello"
Can you do it with proper variables? I tried this, but the syntax doesn't check out:
ActionScript Code:
n=1;
var "myVar_"+n:String = new String("hello");
Any ideas?
View Replies !
View Related
Dynamic Variable Names
Erm.... can you use a variable as a variable name? Say...
variable1 = "variableName";
then...
[ variableName ] = "hello";
trace(variableName);
//Output = hello
? I used to know but I've forgotton.
View Replies !
View Related
Can I Have Dynamic Variable Names?
ok so if i need say 10 instances of my class, i use a loop like this
Code:
for (var i:Number = 0; i<antallevels; i++) {
var allLevels:Level = new Level(_root.levelcontainer, "level");
}
This works but i cant call one of them, since they all have the same name(allLevels)
My guess was something like
Code:
var level_[i]:Level = new Level
or
var ["level_" +i]:Level = new Level
but that gives me a syntax error, so no thats not it.
any idea's ? or am i all wrong in using for loop on this
View Replies !
View Related
Dynamic Variable Names
I am creating a series of graphics in a for loop, naming them, and adding eventlisteners for dragging purposes. I'd like to make a way to access my variables with something like this:
Code:
// This worked in AS2, just not in AS3
for(var i=0;i<6;i++){
this["graphicName_" + i].accessSomeMethodHere;
}
//graphicName_0, graphicName_1, etc.
It is simplified here, but that is the basic idea. Any ideas on how this works in AS3?
View Replies !
View Related
Dynamic Variable Names
I am just trying to dynamically name some variables and I am having some troubles.
var i:String = "One";
var ["hey" + i] = "test";
trace(heyOne);
This is the error message I keep on getting.
1084: Syntax error: expecting identifier before leftbracket.
If anyone could help it would be appreciated.
Thanks
Jeff
View Replies !
View Related
Dynamic Variable Names?
I have some code that looks like this:
ActionScript Code:
//adds the movieclip graphic (exported for actionscript) in the flash library with the same name
//randomInt returns an integer between 0 and param-1
switch (myRandom.randomInt(4)+1) {
case 1 :
addChild(new asteroid1);
break;
case 2 :
addChild(new asteroid2);
break;
case 3 :
addChild(new asteroid3);
break;
case 4 :
addChild(new asteroid4);
break;
default :
throw new Error("switch screwy in constructor");
}
Is there any way to write this code in a loop?
i.e. ("asteroid" + i) = asteroid1, asteroid2, asteroid3, or asteroid4
View Replies !
View Related
Dynamic Variable Names
I have a script that creates a bullet and names it as bullet then the number of shots. Then when I try to change its x position it throws an error.
duplicateMovieClip(_root.bullet0, "bullet"+_root.shots, 0);
_root."bullet"+_root.shots._x = 100;
What corrections do I need to make to get this to work right?
Thanks
View Replies !
View Related
Dynamic Variable Names
I have the following code
ActionScript Code:
si = setInterval(function () { ind++; ind>7 ? clearInterval(si) : null; var tw = new Tween(_root._mc["a"+ind], "_xscale", Regular.easeOut, 0, 200, 60); new Tween(_root._mc["a"+ind], "_yscale", Regular.easeOut, 0, 200, 60); tw.onMotionFinished = function() { new Tween(_root._mc["a"+ind], "_xscale", Regular.easeIn, 0, 100, 40); new Tween(_root._mc["a"+ind], "_yscale", Regular.easeIn, 0, 100, 40); };}, 50);
Basically, it goes through 7 loops and animates each object. My problem is that the onMotionFinished function isnt being triggered because it gets overwritten each time before it can. is there a way to dynamically create a variable name to keep track of each Tween? Something like
ActionScript Code:
var eval("tw" + ind) = new Tween(_root._mc["a"+ind], "_xscale", Regular.easeOut, 0, 200, 60); eval("tw" + ind).onMotionFinished = function() {
except eval appears to only work for objects. Any ideas?
View Replies !
View Related
Dynamic Variable Names?
I want to create a var that concatenates some text with my loop counter, this doesn't work:
Code:
var this["appNm_tf"+i]:TextField = mcMain.createTextField("appNm_tf"+i, getNextHighestDepth() , 0, i * 20, 150, 20);
View Replies !
View Related
Dynamic Variable Names
I'm trying to build a dynamic array.
I can't figure out how to increment my variable name.
I've been sitting here a long time and it feels like my eyes are bleeding.. LOL
springArray[arrayIndex] = [phpIndex+i];
When I use this is outputs NAN, I dunno what that is.
I want to increment phpIndex1 to phpIndex2 then 3 then so on..
Here's the full code.
result_lv = undefined;
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
mystatus.text = result_lv.wrote;
springArray = new Array();
arrayIndex = 0;
phpIndex1 = result_lv.c1;
phpIndex2 = result_lv.c2;
phpIndex3 = result_lv.c3;
i = 1;
do {
springArray[arrayIndex] = [phpIndex+i];
i++
arrayIndex++;
result_lv.myIndex = result_lv.myIndex-1;
} while (result_lv.myIndex-1 ne 0)
// populate the listbox with the data
for(i=0;i<springArray.length;i++) {
spring.addItem(springArray[i][0], springArray[i][1]);
}
} else {
mystatus.text = "Error connecting to server.";
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.id = _global.primary_key;
send_lv.sendAndLoad("http://localhost/Contacts/selectFly.php", result_lv, "POST");
View Replies !
View Related
AS 2.0 Dynamic Typed Variable Names
Hi,
I'm tring to create dynamic var names for a 'Box' class like so:
Code:
for(var i =0; i<3; i++){
set( "box" + i + ":" + "Box", new Box (100+(i*10),100+(i*10),10+(i*10),100+(i*10),_level0,i+10) );
}
This is all fine and dandy, 3 boxes of the proper size, and location are created. The crazy thing is that the variables named box0, box1, and box2 do not exsist! Maybe I shouldn't be using set?, I tried [], and eval to no avail.
the regular line of code that draws a single box from the Box class looks like this:
Code:
var box : Box = new Box (200,100,10,100,_level0,20330);
Any Ideas,
~Dev
View Replies !
View Related
Problems With Dynamic Variable Names.
I want to write code where I have arrays of objects.
I want to write a for loop and have something like:
myObject1 = new Object();
myObject2 = new Object();
myObject3 = new Object();
myObject4 = new Object();
etc...
How can I do this?
I've tried using square brackets... it doesn't work and looks wrong to do anyway.
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
How To Create Dynamic Variable Names?
Hi guys
I want to create a series of variable names dynamically, but don't know how to do it.
for example, i have a for loop, and want to use the "i" value to be part of a new variable name
Code:
for(i=0;i<total;i++){
var variable+i:String = something;
}
the above obviously doesn't work, can someone enlighten me on what would be the right code?
Many thanks
Joe
View Replies !
View Related
[F8] Loop And Dynamic Variable Names
Hi,
I got this loop going, which creates button on my stages dynamically. Now I need to create color transforms for each of those buttons while I'm still in the Loop. So I know this doesn't work, but while I'm in the loop I would like to do something like this:
Code:
CountryText_mc.MainButton.onRollOver = function() {
var myOverColor+[i]:Color = new Color(CountryText_mc.MainButton);
myOverColor+[i].setRGB(0x2be237);
}
CountryText_mc.MainButton.onRollOut = function() {
var myOutColor+[i]:Color = new Color(CountryText_mc.MainButton);
myOutColor+[i].setRGB(0xFFFFFF);
}
How can I create those color variables, so that this would work. I need to have myOverColor1, myOverColor2, myOverColor3,... and so on. So I can set them anytime I want.
Thanks for help
View Replies !
View Related
Dynamic Variable Names In A Loop
Hi, I'm still a noob at as3 and I'm trying to write a script so that I can affect variable names using a loop.
For example:
Code:
var varName;
function test(event:MouseEvent):void
{
for (var i = 0; i < 5; i++)
{
varName = "a" + i;
var a[i]:Number = i;
trace ( varName + " = " + a[i]);
}
}
essentially I want it to display like this:
a0 = 0
a1 = 1
a2 = 3
a4 = 4
a5 = 5
So I was wandering if there was syntax for what I'm trying to do.
View Replies !
View Related
PHP -> Flash With Dynamic Variable Names
Hey there,
I've got a little problem and im not sure how to go about solving it, ive got a PHP file that sends data to Flash... the problem is Flash doesnt know how much data it is going to recieve.
I mean it's easy to do a bit of code that sends a static variable from PHP to FLASH such as:
PHP Code:
echo "&strTextVar=woooooo&";
then flash would go...
Code:
//...Pre init oReturn etc...
strText = oReturn.strTextVar;
That would quite happily get me the variables strTextVar from PHP to Flash and everyones happy... building off this i now want to have a dynamic names variable... well i guess its still static but anyway heres an example of what i mean.
PHP Code:
for($i=0;$i<rand();$i++)
{echo "&strTextVarNo{$i}=woooooo&";}
then flash would go...
Code:
//...Pre init oReturn etc...
strText = oReturn.strTextVarNo0;
Thats spiffing and all works... BUT i want to do a loop in flash, its basically for a cut down chat system i want to make, but PHP gets the chat data from the DB and doesnt know how much chat it will recieve, then flash needs to loop the variables and output them. I'm basically wondering if there is a way to hack together a variable name in runtime opposed to hardcoding it...
i.e replacing the "strTextVarNo0" with "strTextVarNo{$i}".. if that makes sense...
Any feedback would be GREAT!
View Replies !
View Related
How To Create Dynamic Variable Names?
Hi,
I'm making a dynamically created gallery menu, and I need to flag a variable with a value when a dynamically created button is pressed. I know how to create the "onPress" fuction for the dynamically generated button.. I just don't know how to make the text (value given to a variable) be different from other buttons created in the same list. Is there some way to bracket out text that will be calculated / converted into a number that is ultimately added to the function?
Something like this...
A = 1
do{
Gallery.attachMovie("ThumbButton",["Butt_" + A],A + 1000);
Gallery["Butt_" + A]._y = (below last button);
Gallery["Butt_" + A].onPress = function () {Picked = "the conversion of A"};
A++;
} while (List != complete);
then if I click on the 4th button, Picked = 4
Thanks so much!!!!!!!!!!!!!!!!!!!
View Replies !
View Related
Setting Dynamic Variable Names :s
heres the code im working on:
Code:
var temp1 = 1;
var temp2 = "hi";
var temp3 = [temp2+"6"];
temp3 = temp1;
trace([[temp2]+"6"]);
why is hi6 returned?? i need it to return the value 1
temp3 = hi6;
i want the variable to be named that, so effectively hi6 = temp1;
so when i call temp2+6 or hi6 it returns the value of temp1 which is 1;
View Replies !
View Related
AS2 Syntax And Dynamic Variable Names
Hi all,
Trying to learn AS2 and hoping someone can help me by explaining the problems with the following sample code and what would be needed to make it work (i.e. to create dynamic variables and movie clips from an array).
Thanks for your time!
Attach Code
// create array
var myArray:Array = ["a", "b", "c", "d"]
// create variables and movie clips
for (var i = 0; i<stn_Array.length; i++){
var [myArray[i]+"_colour"]:Number = 0xFFFFFF;
createEmptyMovieClip(myArray[i]+"_mc",i)
myArray[i]+"_mc".lineStyle(9,myArray[i]+"_colour")
myArray[i]+"_mc".moveTo(100,100*i);
myArray[i]+"_mc".lineTo(150,100*i);
myArray[i]+"_mc".onRollOver = function (){
//do something
}
myArray[i]+"_mc".onRollOut = function () {
//do something
}
}
View Replies !
View Related
Problems With Dynamic Variable Names.
I want to write code where I have arrays of objects.
I want to write a for loop and have something like:
myObject1 = new Object();
myObject2 = new Object();
myObject3 = new Object();
myObject4 = new Object();
etc...
How can I do this?
I've tried using square brackets... it doesn't work and looks wrong to do anyway.
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
ASP And Dynamic Variable Text Box Names
Having a problem with a Flash/ASP/Database project.
I've seen tutorials that pulls address book listings dynamically from the DB. When you hit "next" button it just populates dynamic text fields with variable names like "name" "address" with the appropriate info.
Problem I'm having is.. what if you want to display all the entries on the same screen.
If the variable names on the dynamic text fields are hard coded named "name" "address" "phone number" etc. , how can the second set of info display underneath the first one properly and not just pull the same text from the first record into the text fields? (name2, address2, etc.)
Is there a way to dynamically change the variable name of a dynamic text field?
I'm thinking you should be able to have it note how many records there are, then loop until it reaches the end of the record set. So, can the variable names be dynamic so it will populate the text fields with the appropriate info?
Any help would be appreciated.
Thanks
ryano
View Replies !
View Related
Problems With Dynamic Variable Names.
I want to write code where I have arrays of objects.
I want to write a for loop and have something like:
myObject1 = new Object();
myObject2 = new Object();
myObject3 = new Object();
myObject4 = new Object();
etc...
How can I do this?
I've tried using square brackets... it doesn't work and looks wrong to do anyway.
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
How To Create Dynamic Variable Names?
Hi guys
I want to create a series of variable names dynamically, but don't know how to do it.
for example, i have a for loop, and want to use the "i" value to be part of a new variable name
Code:
for(i=0;i<total;i++){
var variable+i:String = something;
}
the above obviously doesn't work, can someone enlighten me on what would be the right code?
Many thanks
Joe
View Replies !
View Related
Problems With Dynamic Variable Names.
I want to write code where I have arrays of objects.
I want to write a for loop and have something like:
var user[i]:Object = new Object();
(I used the square brackets because that's the write formate when declaring dynamic variable names in complex variable path names.)
I've also tried the following:
var eval("user" + i):Object = new Object();
Being Flash MX 2004, this didn't work either.
Where am I going wrong?
And how can I do what I want to do?
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
Array Variable Names In Dynamic Text
Am I missing something or can you NOT use variable arrays as the linked variable in a DynaText object?
ex:
If I have a DynaText field with a variable set to "data1" and then do a data1 = dataarray[1] ...this works...obviously.
But if I have the DynaText field variable to to dataarray[1]...it does not display the value of that dataarray[1]
Now, sure, normally I could just assign the DynaTexts to non-array variables and just set their values FROM the array. But, I talking like 100 DynaText fields here. And not being able to directly associate them with array values would be a LOT of unnecessary code and cpu overhead.
Please tell me this is not a limitation in MX...please!
TIA
Ahhhk!
View Replies !
View Related
Incrementing Dynamic Text Box Variable Names
Anyone have an idea on how to increment the variable name of a dynamic text box?
Here is the plan...
I want to create an array of text boxes that are attached to vertices that go round and round in a psuedo-3D. However, I can't quite make out how to increment the dynamic varible text boxes to take more than one value. Any suggestions?
Here is the code where I am duping the text boxes, which seems a likely place to me to change the variable name and assign a new value but I am not sure. Thanks in advance for any assistance.
for (i=0; i != Points; i++) {
point.DuplicateMovieClip("v" add i, (Lines*2)+i);
vertex[i] = eval("v" add i);
//where:
// vertex is the name of the MC in the Library
// point is the name of the instance
// textvar is the variable name of the text box within point
//code should go here i suppose!
//if you need more code to see the bigger scheme of things let me know.
}
View Replies !
View Related
Accessing Dynamic Instance And Variable Names
Version: Macromedia Flash MX Professional 2004
1) I am trying to access certain instances in my flash game that change depending on certain things. Here is an example that I tried:
Works (static case):
_root.projectile1._x = currentGunX;
Doesn't Work (dynamic case):
_root.["projectile" + zLevel]._x = currentGunX;
Only to find out that the creation of the dynamic instance name with ["projectile" + zLevel] does no work in my newer version, so I need help with how to access the dynamic instance.
2) Secondly, I have a variable that I want to access in basically the same case, here it is as a static case:
Works (static case):
currentGunX = _root.controller.GUN1_X;
Doesn't Work (dynamic case):
currentGunX = _root.controller.["GUN" + controller.activeGun + "_X"];
So, all in all, I need the way to dynamically access both instances and variables. Any help is appreciated.
View Replies !
View Related
Arrrgh, Dynamic Names For Array() Or Variable, Please Help
I need to create and assign values to variables/arrays in a 'for' statement, but invariably receive the error message from the Output window:
"Left side of assignment operator must be variable or property."
So I currently have this code.....
// --- START CODE SNIPPET
//
function theLVEvaluator(count)
{
underArray[0] = (TheLV["myPrimaryPic"+count]);
trace("UNIQUE= "+underArray[0]);
underArray[1] = (TheLV["myThumb"+count]);
trace("UNIQUE= "+underArray[1]);
//< etc, etc....>
theArrayBig[count] = underArray;
}
//
// --- END CODE SNIPPET
..... 'theLV' is my loadVars object that is processing a heapof variables returned from mySql via PHP.
In the above code, trace actions confirm that I am looping successfully through all the raw variables (each unique mySql entry gets listed through Trace actions), but of course as I am unable to evaluate new variable names on the fly (see error message above), I end up with an array of 93 identical entries, because the last dataset overwrote all the others.
What I would LOVE to do is:
("'underArray"+count[0]) = (TheLV["myPrimaryPic"+count]);
..but I just get told the same old thing about the left side of the assignment operator having to be a variable or property. This is grinding me down over the days, does anyone have any suggestions?
PS: I am using the PHP output saved as a text file to emulate live server data in the debug/testing window in Flash.
View Replies !
View Related
Creating Dynamic Variable Names In Loop
I want to do is to create a new variable appended with a number going thru a loop as so:
Code:
var test = "test";
for(var i=0;i<3;i++)
{
//Create a new variable called test0,test1 and test2 with the value of "test"
var test = [test + i]; //this is wrong
}
//Print out all of the variables test0,test1,test2 which should produce 3 test strings in the output
for(var i=0;i<3;i++)
{
trace(test0);
trace(test1);
trace(test2);
}
Any ideas anyone
View Replies !
View Related
Dynamic Instance/Variable Names In Loops
This has been bugging me for a while but I'll have a series of movieclips, variables, input boxes, or whatever with a name then a number as their names. For example input0, input1, input2, etc. In AS2 I could throw them into a loop like so:
Code:
for(i = 0; i<3; i++)
{
this["input"+i].text = array[i];
}
...or something to that regard. How do I do this in AS3 where I can set up a loop and dynamically call the numbered instance name?
View Replies !
View Related
Dynamic Variable Names - Need Syntactical Clarification
I'm familiar with the AS 2.0 and php methods of creating dynamic variable names but AS 3.0 doesn't seem to subsribe to all of their functionality needs.
Let's use the example below:
Code:
$infoPanelStatInitialLoc = new Object;
$infoPanelStatInitialLoc.x = $root.ui.info_panel_stats.x;
$infoPanelStatInitialLoc.y = $root.ui.info_panel_stats.y;
$infoPanelKillInitialLoc = new Object;
$infoPanelKillInitialLoc.x = $root.ui.info_panel_kills.x;
$infoPanelKillInitialLoc.y = $root.ui.info_panel_kills.y;
$infoPanelFactionInitialLoc = new Object;
$infoPanelFactionInitialLoc.x = $root.ui.info_panel_faction.x;
$infoPanelFactionInitialLoc.y = $root.ui.info_panel_faction.y;
You'll see some similarities such as the path and the variable names. What I'd like is to do something with a little less code using dynamic variable names, such as:
Code:
panelName = 'whatever';
for(var i:Number=1;i<=3;i++)
{
this[panelName] = new Object;
this[panelName].x = $root.ui[panelPath].x;
this[panelName].y = $root.ui[panelPath].y;
}
or perhaps like this, if you're familiar with php
$panelName = 'whatever';
for($i=1;$i<=3;$i++)
{
${$panelName} = new Object;
${$panelName}.x = ${'$root.ui.'.$panelPath.'.x'};
${$panelName}.y = ${'$root.ui.'.$panelPath.'.y'};
}
If there are minor code mistakes, forgive me. This is just psuedo code and not to be taken for exact examples. What I'm looking for is a way in which i can use my own dynamic variable names to items that aren't necessarily added to the displayObject.
Any ideas?
View Replies !
View Related
Eval Button Names?
heya,
i am using this:
Code:
var btn_name = this["test_btn"+i];
to create a button name. but now the buttons are nested inside of a container. so i tried
Code:
var btn_name = this["container.test_btn"+i];
but it doesn't seem to be working... any advice?
thanks,
kris
View Replies !
View Related
Pass URL String From External File To AS Variable (dynamic File Names)
I have a movie player that works fine when i hard-code the url value in the video function, but when i try to pass that url/file path from an external file, the video doesn't load. I suspect that there is something i'm doing wrong with the quotes. What am i doing wrong?
Code:
var vfile:String = string("path");
supervideo = function () {
var netConn:NetConnection = new NetConnection();
netConn.connect(null);
var netStream:NetStream = new NetStream (netConn);
video.attachVideo(netStream);
netStream.setBufferTime(10);
netStream.play(vfile);
};
loadText.load(_global.text_url1);
loadText.onLoad = function(success) {
if(success){
showtitle.text = this.title1;
vfile = this.flv_name;
supervideo();
}
}
The value in the php file looks like this:
PHP Code:
&flv_name="elements/flv/superape.flv"&
So ultimately i want to end up with netStream.play("elements/flv/superape.flv");. I know the value of vfile is being passed from the php file and getting into the supervideo(); function because i have a textbox echoing vfile. I have tried defining the variable with and without the ":String". Please let me know if you can see any errors. Thanks!
View Replies !
View Related
Using Eval() Variable?
I am passing several values between movieclips. Movie clip A (a dropdown menu) passes an _x position number to movie clip B. On movie Clip B, I run a trace() and see the passed value, e.g 263.3.
However when I attempt to use that value on movie Clip B, it appears to be inaccessible.
I have tried various combinations of actionscript, including eval(), but the value just isn't being read.
Here's the code on MC "B"
trace('TabX' + tabx); // this displays 263.3 when run.
tfopen._x=eval("tabx"); //should reposition the orginal menu to
263.3. Instead x appears to default to 0
View Replies !
View Related
Using Eval() Variable?
I am passing several values between movieclips. Movie clip A (a dropdown menu) passes an _x position value to movie clip B. On movie Clip B, I run a trace() and see the passed value, in this case 263.3.
However when I attempt to use that value on movie Clip B, it appears to be inaccessible.
I have tried various combinations of actionscript, including eval(), but the value just isn't being read.
Here's the code on MC "B"
trace('TabX' + tabx); // this displays 263.3 when movie run.
tfopen._x=eval("tabx"); //should reposition the orginal menu to
263.3. Instead x appears to default to 0, throwing the movie out of position.
So what I am missing here?
View Replies !
View Related
Apply Variable Values To Variable Names?
I have a gallery with a series of 5 thumbnails, named gallery_position_1, gallery_position_2, etc, up to 5. I am loading an image with XML into gallery_position_(#), and have a button on top of that with scripts on it.
My question is whether I can have an integer variable (call it x) that starts at 1 and can be put into a for loop, using it then on the end of my other variable like so:
for (x = 1; x < 6; x++) {
gallery_position_x.loadMovie(URL path to image);
}
I basically want to be able to "index" a regular variable by changing a number within its name. I know its a long shot, as I've never seen it done before, but I thought I'd ask, all the same.
View Replies !
View Related
Set A Variable Equal To An Eval Statement ?
I have this statement...
eval("_root.container" + _root.totalContainers)
to define containers because I make a bunch of them...
Can i do something like...
Set TempContainer = eval("_root.container" + _root.totalContainers)
So i can use TempContainer._x TempContainer._y instead of writing it all out every time?
View Replies !
View Related
Problems With Eval() And Loop Variable
okay, i'm trying to dynamically populate the value ot a text
field using a FOR loop. like this.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
Code:
for (i = 1; i <= 31; i++) {
eval("movieClip_" + i + ".textField.text = '" + i + "'");
}
this doesn't produce any output in the swf file. i believe
it's because of the eval function, because if i run a TRACE,
it comes back correct.
any ideas ???
View Replies !
View Related
Dynamically Seting A Variable ... In MX Eval() No Longer Works :(
in the old days of Flash 5, you could dynamically set a variable using the eval() function. What am I talking about? - here ...
For example, if I created a movie clip using duplicateMovie() as follows :
Code:
for (i=0; i<playList.length; i++) {
thumbNum = playList[i][1];
duplicateMovieClip("menu.thumbClip", "thumbClip" add thumbNum, i);
}
I could then set a variable (in this case called 'test') to that new clip as follows :
Code:
eval("menu.thumbClip" add thumbNum add ".test") = "toast";
This can no longer be done in MX, and I can find NO documentation on this method ... boo hoo ... any one know how i can do this in MX??
Thanx in advance,
Jamin.
View Replies !
View Related
Variable Names Are Part Of A Variable Itself
hello,
i ahve a deadline and im in a bit of a mess, i was wondering if anyone knows the awnser to this one.
i am targeting a variable in another movie the name of the variable is ' ysh1 ' this is a score and the is 9 other they are ' ysh2 ' , ' ysh3 ' etc.
and a variable on the main time line called ' hole ' ,
it's value is ' 1 '.
this is the variable that targets ' ysh1 '.
set ("_level0.display.score.ysh"+_level0.hole, "_level0.display.score.ysh"+_level0.hole+"+1") ;
so it does target the variable, that works fine but i cant make the score increase by 1
im just try to increase the score by one evey time this function is called.
it's driving me mad.
any help would be great.
View Replies !
View Related
Variable Names
ok, I'm a bit of a flash n00b.
I was trying to create global variables named using a combination of a word and an identification number, but I can't figure out how to phrase it properly. The part in red is my problem. If this worked properly it would create global variables named mass1, mass2, mass3 etc.
Code:
for (var i = 0; i<_root.totalorbs; i++) {
_root.["mass"+i] = _root["orb"+i]._mass;
}
View Replies !
View Related
Variable Names
ActionScript Code:
storycontent0 = "Day 1 - The Carnage Starts
The first day";
idnumber = 0;
story = this["storycontent"+idnumber]
this sets story to storycontent0.
however i need my menu button to set the content which is two levels above the timeline
ActionScript Code:
this.onRelease = function(){
_parent._parent.storycontent = _parent._parent.["storycontent"+idnumber]
}
this doesn't work! i've tried different types but can't get it to work - any ideas?
Cheers,
Matt
View Replies !
View Related
|