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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alias issue using "this" 3

Status
Not open for further replies.

SimJim

Programmer
Apr 7, 2003
26
0
0
KR
I want to call a routine from my main timeline using a loop structure. I have nested the MC in a Scroll Pane and thus the prefix "_root.SP01.tmp_mc". The iPTx MC is one of many instances I need to scan through and update. Why does Flash tell me that "alias" is undefined?

Any resommendations for another technique? Am I mixing modes by adding a number to the string, or is a path actually a string?

for (i=1, I<=12, I++){
alias = this[&quot;_root.SP01.tmp_mc.iPT&quot; + i];
trace(alias);
alias.mc01.gotoAndStop(&quot;off&quot;);
alias.mc02.gotoAndStop(&quot;on&quot;);
alias.mc03.gotoAndStop(&quot;off&quot;);
}

Thanks,
 
There are three things that come into my mind.

Firstly you use caps and lower case in you for-statement.

Secondly you cannot use a path starting with &quot;this&quot; and going on with _root since _root addresses the main timeline.
When starting with &quot;this&quot; you can only address movieclips within the clip you put the &quot;this&quot; on.

Thirdly I'd use ' within the brackets [] instead of &quot;.

I guess that should make you come closer to the solution. If my tip was not sufficient please check back and tell me.
(or ask wangbar who is one of the syntax-checkers in my eyes :))

regards

tektips.gif
 
firegambler,

Actually I just stuck the for loop in the the thread to explain the desired use. I did bugger the script though. Regarding the &quot;this&quot; use. How do create an alias to refer to a several instanced targets at the same level using a variable in the path?

&quot;SP01&quot; is the scroll pane
&quot;tmp_mc&quot; is the replacement the scroll pane gives you for the linked instance.
&quot;iPTx&quot; is my target instance where &quot;x&quot; is what I want to change as I go through the loop.

alias = this[&quot;SP01.tmp_mc.iPT&quot; + i];
trace(alias);
alias.mc01.gotoAndStop(&quot;off&quot;);
alias.mc02.gotoAndStop(&quot;on&quot;);
alias.mc03.gotoAndStop(&quot;off&quot;);

Thanks
 
Try a path in this format: SP01.tmp_mc['iPTx'+i]

 
actually i got the impression to be a little weak in comprehension on that whole topic of creating those paths dynamically...

wangbar, what does the &quot;x&quot; after &quot;iPT&quot; stand for in your suggestion.
unfortunately i'm a nitwit in that issue.

would the correct example of scripting be:

Code:
for(i=1;i<10,i++){
myclip.mysubclip['subsubclip'+i]gotoAndStop(1);
}

another thing that is not too clear for me:
why needn't i use some dots in front of and after the squared brackets? regards

tektips.gif
 
firegambler,

wangbar was repeating my string for me, see my question posed above these last three posts. The &quot;x&quot; was there to indicate that this clip had several instances, which is what I wanted to be able to call from a loop structure on the main timeline.

Thanks to both of you!
 
firegambler & wangbar

I tried the following:

//This is a test of the path and it works fine
fader = _level0.SP01.tmp_mc.iPT1.mc1.iRknob;
fader._y = Rght;

//This is a test of the same path and it does not work
//The error says it is looking for a &quot;;&quot;
for(i=0; i<3; i++) {
fader = _level0.SP01.tmp_mc['iPT' + i]mc1.iRknob;
fader._y = Rght;
}
 
wangbar & firegambler

I'd post it, but I'm not web savvy yet. Maybe I can learn enough Dreamweaver to start a decent site over the weekend.

Anyway, the trick with: tmp_mc[&quot;iPT&quot; + i] is that it must be at the end of the command. In other words, the end bracket must be followed by the &quot;;&quot; or it will complain. So I just created the aliases (LftPnt & RhtPnt) to point to the first part of the path string and then attached the remaining path info (.mc1.iLknob._y) in the next line.

//The code on the main timeline
this.onEnterFrame = function() {
// just using the sin & cos to test my sliding buttons
// iLknob & iRknob below
x+=.02;
c=Math.cos(x);
Left=c*50-125
s=Math.sin(x);
Rght=s*50-125
//trace(x);
for(i=0; i<=3; i++) {
//this works flawlessly
//the knobs are sliding up and down at
//a nice smooth rate for all
//instances iPT1, iPT2, iPT3, etc.
LftPnt = _level0.SP01.tmp_mc[&quot;iPT&quot; + i];
LftPnt.mc1.iLknob._y = Left;
RhtPnt = _level0.SP01.tmp_mc[&quot;iPT&quot; + i];
RhtPnt.mc1.iRknob._y = Rght;
}
if (x > 255) {
x = 255;
}
}

Questions: Why the ' instead of &quot; in your example, and is it actually possible to put the [] in the string w/o the aliases, or must the closing brace be followed by the &quot;;&quot;?
 
Why the ' instead of &quot; ? Just because I think it looks better :)

It's not like PHP where ' and &quot; have different effects on how a string is processed etc.

Not sure if I'm understanding the second part of your question, but if you mean can you do this:

SP01.tmp_mc[&quot;iPT&quot; + i].mc1.iLknob._y = Left

Then yes you can.



 
The dot syntax replaces the [] syntax. They are synonymous. If you us the brackets to refer to an instance, then you don't use the dot, as in _root[myInstance]. However, if you refer to a property or function of myInstance, and still want to use the [], then you also use the dot, as in _root[myInstance]._x. I hope that answers your question firegambler, if wangbar didn't explain it completely for you.
 
Thanks FlashMax, that was it exactly!
Worth a star for you!! regards

tektips.gif
 
Flashmax,

One question. following your comments on the dot versus the []. See the example from Wangbar above.

SP01.tmp_mc[&quot;iPT&quot; + i].mc1.iLknob._y = Left

This is true and I tried it yesterday.

However it goes against the strain in that mc1 and iLknob are not properties or functions, and yet the dot was still necessary. Is it possible that your comment only applies to the leading bracket, but that the ]. is still always required? Or is it that the string is ultimately pointing at a function as its purpose and therefore needs the ]. instead of just ]?
 
The first brackets do not require the leading dot syntax, as in _root[myInstance]. However, after that, especially when referring to functions of and properties of myInstance, you would use the dot notation. The same as in _root.myInstance._x. I think that in their example they are not referring to the full string name are they?
 
It is the full string. However, let's say that I want to refer to an object using the &quot;with&quot; syntax. Will that still work. So that I can avoid the long path over and over?
 
yip with is a good command

with (pathToMovieClip) {
_x = 50;
_y = 100;
//etc etc
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top