PDA

View Full Version : variables in attached mc?


annette
07-02-2004, 05:27 PM
Im trying to use a text effect by tommywizbang in an mc called to the stage by attachMovie.

He has two dynamic text boxes with variables"tf" and "tf_max" and the following script in the first frame of the main timeline:

this.onLoad = function() {
tf = "";
text = "blahblah";
_root.tf_max = text.length;
speed = 6;
};

this.onEnterFrame=function() {
if (_root.tf_max<=1){
output = substring (text,1,-1);
tf = output;
break;
} else {
tfLength =_root.tf_max-speed;
_root.tf_max = tfLength;
output = substring (text, tfLength, speed);
tf = output+tf;
}
};

MovieCliip.prototype.reset = function(){
tf = "";
_root.tf_max = text.length;
};

I cant understand why he has only one variable referenced to the _root but also if I remove the reference to _root for tf_max, his code still works when I test my mc scene. When I test the movie, my attached mc flashes up for a second and then dissappears.

I've tried addressing the 'onLoad' and 'onEnterFrame' actions as _root.holder.mc.onLoad etc (holder is the emty mc that attaches my mc) or as _parent._parent. I've also tried changing the paths to the variables and at one stage tried to set global variables. I'm not sure if this was the right way to go because I thought if a variable was declared in a movie clip you could use it in that movie clip without having to set a path to it. But when get the output window to list variables it dosent list values for variables in the attached mc.

I know this is a basic addressing problem but I've trawled though tutorials and the forums to try and figure out what I'm doing wrong and cant seem to get it to work.

Cota
07-02-2004, 05:37 PM
Have you tried changing "_root" to "this"

annette
07-02-2004, 07:44 PM
yes I have but it doesnt work

Cota
07-02-2004, 08:13 PM
If its an attached movieclip, try refering to it by its absolute path. For example, _root.instanceName.tf_max

divarch
07-02-2004, 08:27 PM
Have you embedded the fonts?
:)
Stupid wild guess, but won't hurt...
As cota said, if you declare the function on the main timeline, then '_root' is the same as 'this'. I know you know that, just making sure.
Those path probs can be a major drag sometimes.

annette
07-02-2004, 09:43 PM
The code works when I test scene but not when I test movie.

The functions are not declared on the main timeline. I copied tommywizbangs code and dynamic text boxes to an mc that is called to the stage by attachmovie.

I did try to refer to the absolute path _root.holder.mc.tr_max on the onload and enterframe action. It didnt work. I also tried various permutations to address the variables - _parent, _this etc. The dynamic text boxs have just the var refs - I also tried giving them instance names as well but when I test the movie the "list variable" output window shows that the script is running but there are no values for the variables.

divarch
07-02-2004, 09:53 PM
Well, maybe the best would be to zip the file up and post it here.
It could be pathing, maybe something else... Is the movie even being attached?.. dunno..
post the file, and will try to help

annette
07-03-2004, 02:03 PM
a bit lame but I dont have a zipping prog so I've attached tommywizbangs zipped fla.

All I've done is moved the code and dynamic text boxes into an mc which is called to the stage via attachmovie - path being _root.holder.mc. I know that the movie is being attached because I have been checking the debug 'list objects' and 'list variables'. I have also run trace actions so I know the onload and onEnterframe events are being triggered. The problem is that the tf, tf_max, speed variables are not being initialised.

I wander if the problem may be that the variable field in the dynamic box inspector needs to incorporate a path eventhough the actionscript uses the relative path 'this'? Also if I give the dynamic boxes instance names what is the correct way of addressing the variable? I'm lost to put it mildly.

CyanBlue
07-03-2004, 02:17 PM
Um... Where is your attachMovie function???

If the file that you have uploaded is not your version, that won't help much... Either go get a WinZip to zip up YOUR file or rename your FLA file to yourfilename.fla.zip and upload it...
(How did you unzip that ZIP file without the utility??? I'm curious... :rolleyes: )

divarch
07-03-2004, 02:38 PM
(How did you unzip that ZIP file without the utility??? I'm curious... :rolleyes: )
:D

Hey annette, just another wild guess...
You have XP and have extracted the file with a rightclick>extract ... so XP has an in-built zipper. To zip, go rightclick>send to>compressed folder

:)
Or do what CB said

annette
07-03-2004, 05:55 PM
I have a mac running mac os x - safari automatically decompresses. very sore point as its just taken me 3 hours to get back - safari was refusing to browse and it looks like I might have problems with my mac. Dont want to piss anyone off- I think I had better abandon this - thanks all for trying to help

annette
07-07-2004, 02:22 PM
Took a break for a few days and regained my composure - I was really winding my self up. I'm now a very happy bunny and if it will help anyone the problem was not with the variables but with the this.onLoad event which wasnt being triggered - I had put traces after this.EnterFrame and assumed that because the trace worked the this.onLoad event had been triggered. not!

I removed all references to _root for the variable tf_max and with the help of Cyan Blue's work round on this thread
createEmptyMovieclips and onLoad Event (http://www.actionscript.org/forums/showthread.php3?s=&threadid=17664)
I changed:

1) the onLoad event to onEnterFrame so it became

this.onEnterFrame = function() {
tf = "";
text = "blahblah";
tf_max = text.length;
speed = 6;
//inserted this action
delete this.onEnterFrame;
};

2) I moved the second onEnterframe event to the second frame of the timeline and inserted a stop action so it became

stop();
this.onEnterFrame=function() {
if (tf_max<=1){
output = substring (text,1,-1);
tf = output;
break;
} else {
tfLength =tf_max-speed;
tf_max = tfLength;
output = substring (text, tfLength, speed);
tf = output+tf;
}
};

Dont quite understand why the onLoad event doesnt work in this scenerio but Cyan Blues work round definitely did for me!