-
eval
i have:
var city = london;
var citytext = eval(city+"text");
that works well.
now i have
var city = londontext;
var city = eval(city-"text");
that doesnt give me the result i was looking for.
is there a way to do this?
-
you cant use maths with Strings
The + when used with a string "concatenates" them togther, basically sticks them together i.e.
trace("1"+"2") // gives "12" not 3
You need to use some string manipulation code to get what you want.
The below code extracts the strings from the instance of "London" to the end of the string and vice versa
myString="helloLondon"
Temp=myString.substr( myString.indexOf( "London", 0 ), myString.length )
trace(Temp)
Temp=myString.substr( 0, myString.indexOf( "London", 0 ) )
trace(Temp)
Hope this helps, could be worth looking for string manipulation tutorials if the above code doesnt make sense.
-
also, eval is a bit dated now. Use array notation instead:
eval(city + "text")
becomes:
this[city + "text"]
and
eval ("_root." + myVariable + "._alpha")
becomes:
_root[myVariable]._alpha
Hope that makes some sense - n.
-
sting comes from property
thanx, your code did work- but i am not inputting the actual sting so it didnt work when i wrote the folowing:
myString=_name;
suffix=myString.substr( myString.indexOf( "text", 0 ), myString.length );
trace(suffix);
Temp=myString.substr( 0, myString.indexOf( "text", 0 ) );
trace(Temp);
var city = _parent.vienna;
var citytext = eval(city+"text");
var citybg = eval(city+"bg");
_parent.highlight(city,citytext,citybg);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|