Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval() correct?

Status
Not open for further replies.

firegambler

Technical User
Sep 25, 2002
455
AT
hi, can anybody please tell me if i used the eval-action correctly

Code:
if (warten2>zeit2) {
		zeit2 = warten2+8000;
		bgaktuell = eval("_level1.bg.clip"+_level0.menuepunkt+".flames");
		bgaktuell.play();
		trace(bgaktuell);
	}


...well i guess not, otherwise the trace action wouldn't tell me "undefined"...
do you probably know how to make this path work? i mean i know the path would be correct if the "eval" action was used correctly, i tried that by writing the full code instead of using some "for" action, but i just cannot figure out how to generate this path with the "for"action
(_level0.menuepunkt is a number from one to six depending on the menubutton pressed)

thanx in advance!!
regards

Firegambler
 
im sure that everything within the eval statement must be a variable.

doesnt look like that is the case.

what is it you are trying to do ?
 
Straight from the manual
eval

Availability


Flash Player 5 or later for full functionality. You can use the eval function when exporting to Flash Player 4, but you must use slash notation, and can only access variables, not properties or objects.

Usage


eval(expression);
Parameters


expression A string containing the name of a variable, property, object, or movie clip to retrieve.

Returns


Nothing.

Description


Function; accesses variables, properties, objects, or movie clips by name. If the expression is a variable or a property, the value of the variable or property is returned. If the expression is an object or movie clip, a reference to the object or movie clip is returned. If the element named in the expression cannot be found, undefined is returned.

In Flash 4, the eval function was used to simulate arrays; in Flash 5, it is recommended that you use the Array object to simulate arrays.

You can also use the eval function to dynamically set and retrieve the value of a variable or instance name. However, you can also do this with the array access operator ([]).

Note: The ActionScript eval action is not the same as the JavaScript eval function, and cannot be used to evaluate statements.

Example


The following example uses the eval function to determine the value of the expression "piece" + x. Because the result is a variable name, piece3, the eval function returns the value of the variable and assigns it to y:

piece3 = "dangerous";
x = 3;

y = eval("piece" + x);
trace(y);

// Output: dangerous
////////////////////////////////////
you cannot add 2 paths togeter within an eval statement
eval("_level1.bg.clip"+_level0.menuepunkt+".flames");

If you just want to get the target you can use this :
Availability
Flash Player 4.

Usage


myMovieClip._target
Description


Property (read-only); returns the target path of the movie clip instance specified in the MovieClip parameter.

Thanks
Tricia
yorkeylady@earthlink.net
 
what i am trying to do is the following. i have several backgrounds in a movieclip that is sliding and finds its position according to the variable _level0.menuepunkt.
this variable changes when a button in the menu is clicked.
the range is from one to six (as i have 6 buttons in my menu) the backgrounds have some animations in it.
i want to play the animation after a specified time again and again after say 8 seconds.
i do only want to play the animation in the current background so that the cpu doesn't get charged too much.
that is why i want to make the path target only the animation in the current background's movieclip.

now i need a way to generate the path to the animated clip
(which is in level1 where my backgrounds are loaded in)
dynamically using my variable _level0.menuepunkt
so that when i click button one the path looks like
_level1.bg.clip1.flames, clicking button two should result in _level1.bg.clip2.flames and so on.
the number after "clip" is the current value of _level0.menuepunkt.
is there a way to generate this path according to the button that has been clicked?

it might seem as if this was a little long winded.
i want to do this because i already have a movieclip containing a timer in level9
so i saw no sense in installing a second, third (and so on) timer in each button running all the time
to make the animation run.

i'd like to make the movieclip's timer in level9 control the animation of the backgrounds too and
avoid putting movieclips containing timers into the buttons that would stress the users cpu with
another 6 onClipEvent(enterFrame)-actions.

please, any suggestions? regards

Firegambler
 
I may be missing something but as there only appear to be 6 possible paths according to which button is clicked then why not pass the path from the button.

button 1

on (release){
//whatever
_root.path = "_level1.bg.clip1.flames";
//or a function call
path(_level1.bg.clip1.flames);
}

or am i missing something crutial
 
well, i might have been a little confusing in my description.
the animation of the background should be recurrent after a specified time, that's why i want to make another object that already has a timer in it for (some other purpose) control the animation in the backgrounds. regards

Firegambler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top