View Full Version : Quick syntax fix - AS2
iceflyin
07-27-2007, 04:03 AM
What am I doing wrong here?
//Doesn't work
Title+[i] = titleArray[i];
Title[i] = titleArray[i]; //Obviously doesn't work.
'Title'+i = titleArray[i]; //Nope...
('Title'+i) = titleArray[i]; //Nada...
//Works for a single variable - But, I would have to write out a ton of these... Cuz, this is used in a loop.
Title0 = titleArray[i];
Edit:Well, this works... Kinda odd workaround though. :/ I have to use two steps, and it should be one...
titleVar = 'Title'+i;
this[titleVar] = titleArray[i];
StupidRalph
07-27-2007, 06:38 AM
What error were you getting? I don't know if you can have that on the left side of the equal sign. It looks like you can benefit from using the WITH statement. documetation (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary826.html)
Well, in all honesty, I'm using tellTarget but I'm going to switch to using with as soon as I understand it more. I've started a thread about this not to long ago.
iceflyin
07-27-2007, 06:43 AM
I'm simply trying to split an array and assign it to multiple variables.
var1=arrayPart[1]
var2= arrayPart[2]
etc...
This is actually the same workaround I used for this problem years ago, now the question is... Is this fixed in AS3? That would give me a reason to upgrade!
StupidRalph
07-27-2007, 07:54 AM
In all honesty, I don't really know the differences between versions. Not sure if I've use Flash enough to upgrade quite yet. But I'm getting my feet wet and I'm becoming a little more comfortable with it.
However, AS3 did have the sound spectrum which I was definately interested in. I think it'll be cool to build an actual graphic equalizer for the mp3 player I just built.
Omnis
07-28-2007, 06:48 AM
Using the eval() function should work. For references see the ActionScript Dictionary (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary200.html) or LiveDocs (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00005702.html) at Adobe.
for (i=0; i<=3; i++) {
eval("title" + i) = titlearray[i];
}
Btw I'm using Flash 5, which has been around for a while and uses AS1 :).
StupidRalph
07-28-2007, 07:31 AM
You're all over the place with the eval()...I came here to comment but looks like you beat me to the punch.
iceflyin
07-28-2007, 11:16 AM
Using the eval() function should work. For references see the ActionScript Dictionary (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary200.html) or LiveDocs (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00005702.html) at Adobe.
for (i=0; i<=3; i++) {
eval("title" + i) = titlearray[i];
}
Btw I'm using Flash 5, which has been around for a while and uses AS1 :).
Hum, no luck... The thing is, I'm not setting a variable... I'm setting a textfield property. Btw, I'm using CS3-AS3.
//Nopers...
this.eval('Title'+i).text=titleArray[i];
this.eval('URL'+i).text=urlArray[i];
//Nope....
set(this('Title'+i).text,titleArray[i]);
set(this('URL'+i).text,urlArray[i]);
Ahh, Ill juse use my current code until I find something better that works.
//Works nicely, but... I swear there must be a way to do this with half the code...
for (var i=0; i<=titleArray.length-1; i++) {
var titleVar = "Title"+i;
var urlVar = "URL"+i;
this[titleVar].text=titleArray[i];
this[urlVar].text=urlArray[i];
}
Omnis
07-29-2007, 11:03 AM
You're all over the place with the eval()...
Well a lot of people don't know about it :p and its particularly useful
Hum, no luck... The thing is, I'm not setting a variable... I'm setting a textfield property. Btw, I'm using CS3-AS3.
Whether your using AS1/AS2/AS3 they're all based on the ECMA-262 (http://en.wikipedia.org/wiki/ECMA-262) specification, with each version of ActionScript becoming more refined (more like replaced) and extended, more info can be found on the Wikipedia (http://en.wikipedia.org/wiki/ActionScript#Time_line_by_ActionScript_version). Anyway after checking out some CS3 documentation here (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00005514.html), here (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000222.html) and here (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000881.html), I've come to a conclusion: ActionScript Continuity Sucks! - but heres your solution nonetheless :)
for (var i=0; i<=titleArray.length-1; i++) {
eval("this.Title" + i + ".text") = titleArray[i];
eval("this.URL" + i + ".text") = URLArray[i];
}Hopefully this Works :rolleyes:
iceflyin
08-07-2007, 02:06 AM
No go!
Error: #1084: Syntax error: expecting rightbrace before semicolon.
Thats for line two.
Omnis
08-10-2007, 12:32 PM
If you've got some spare time could you please try these out. Both should work, which one you choose is up to you :thumbsup:
for (var i=0; i<=titleArray.length-1; i++) {
eval("this.Title" + i).text = titleArray[i];
eval("this.URL" + i).text = URLArray[i];
}
or this
for (var i=0; i<=titleArray.length-1; i++) {
this["Title"+i].text = titleArray[i];
this["URL"+i].text = URLArray[i];
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.