-
Help - I must be making syntax error
Hi, just wondering what I’m doing wrong. I have the following actionscript: (please note that callevel, cal_ab, and cal_y are global variables).
on (release) {
callevel.slider_movie.cal_ab._y= cal_y;
trace ("check my variables "+callevel+cal_ab+cal_y);
}
When a button is pushed I want the _y property of a movie clip to change so that the clip moves. The trace is picking up all the variables ok but the code callevel.slider_movie.cal_ab._y= cal_y; doesn’t seem to be changing the _y property. If I enter the values of the variables into the line of code then the _y property updates and the movie clip moves. So entering the following works: _level2.slider_movie.a._y= cal_y;
Does anyone know what I’m doing wrong?
Cheers
-
[callevel].[slider_movie].[cal_ab]._y= cal_y;
I think, anyway.
-
No sorry, it didn't work, I tryed:
[callevel].slider_movie.[cal_ab]._y= [cal_y];///
///(please remember that slider_movie isn't a variable).
I got this error:
Scene=Scene 1, Layer=buttons, Frame=1: Line 2: Expected a field name after '.' operator.
[callevel].slider_movie.[cal_ab]._y= [cal_y];
-
Assuming that "_level2.slider_movie.a._y= cal_y;" works, and assuming the following:
callevel = "_level2"
cal_ab = "a"
cal_y = (some number)
then
[callevel]slider_movie.[cal_ab]._y = cal_y;
The brackets mean "use whatever value is inside here as a label (name), not a value." We used to call this indirect addressing, but I think they're called pointers now. Pointer as in "use what I'm pointing at."
I forget where you do and don't need the dots. I think the above is correct. If not, try playing with the dots around [cal_ab] as well.
Edit: Note there is no dot after [callevel] and no brackets around cal_y
-
Hi Level
My variables
_global.callevel = _level2;
_global.cal_ab = a;
_global.cal_y = a value;
on (release) {
_level2.slider_movie.a._y= cal_y;
}
When I use the above line of code it works fine. When I used the code below it doesn't.
on (release) {
[callevel].slider_movie[cal_ab]._y=cal_y;
}///this was the only configuration of dots that Flash seemed to accept.
Any new light on this?
Cheers
-
We need to get this working, so I'm going to give you my "universal approach" to problems like this.
First, build your string for doing the pointing:
foo:String = _global.callevel + ".slider_movie." + _global.cal_ab;
[foo]._y = cal_y;
/* again, I'm not sure about the dot in [foo](dot)_y. Maybe you need it, maybe you don't. This method (building before converting) is easier to get right.
*/
You'll notice that this also lets you say [foo]._x as well, without retyping a million things.
THAT should work.
Of course, change "foo" to any name you want.
-
Senior Member
The correct syntax is
code:
this[callevel].slider_movie[cal_ab]._y = cal_y;
When creating paths your variables need to go in brackets, and dots only go after the end bracket.
this[callevel] references _level2, remember you always need the parent Movie Clip in front of the bracket, or here when trying to create a level, 'this' goes in front. Then slider_movie, then your other variable, cal_ab, so slider_movie[cal_ab].
-
You guys are great, copied and pasted in:
this[callevel].slider_movie[cal_ab]._y = cal_y;
and it worked - the movie clip moved (I would never have thought of putting 'this' at the front of the code.
Thank you both for your help and suggestions.
Cheers
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
|