PDA

View Full Version : _root issues


netfuel
10-01-2007, 05:43 PM
First for the code that is working:


_qulaity = "best";
function pauseMe(time) {
stop();
pauseinterval = setInterval(pausefunction, time*1000);
function pausefunction() {
clearInterval(pauseinterval);
play();
}
}

import mx.transitions.Tween;
import mx.transitions.easing.*;

function animateFrame(num:Number, xPosPic1:Number, yPosPic1:Number) {
var prevNum = num-1;
//fase last out
var alphaP1:Tween = new Tween(_root["pic"+prevNum], "_alpha", None.easeOut, 100, 0, 1, true);

//animate pic
var xPosP1:Tween = new Tween(_root["pic"+num], "_x", None.easeOut, xPosPic1, _root["pic"+num]._x, 7, true);
//var yPosP1:Tween = new Tween(_root["pic"+num], "_y", None.easeOut, yPosPic1, _root["pic"+num]._y, 4, true);
var xscaP1:Tween = new Tween(_root["pic"+num], "_xscale", None.easeOut, 100, 90, 7, true);
var yscaP1:Tween = new Tween(_root["pic"+num], "_yscale", None.easeOut, 100, 90, 7, true);
}

function tweenFrame(num:Number, xPosPic1:Number, yPosPic1:Number) {
//animate pic
var xPosP1:Tween = new Tween(_root["pic"+num], "_x", None.easeOut, xPosPic1, _root["pic"+num]._x, 7, true);
//var yPosP1:Tween = new Tween(_root["pic"+num], "_y", None.easeOut, yPosPic1, _root["pic"+num]._y, 4, true);
var xscaP1:Tween = new Tween(_root["pic"+num], "_xscale", None.easeOut, 100, 90, 7, true);
var yscaP1:Tween = new Tween(_root["pic"+num], "_yscale", None.easeOut, 100, 90, 7, true);
}

tweenFrame(0, -60, -100);

pauseMe(6);


The issue is that I am using a frame swf to load these guys in randomly and at intervals. So since I am using _root none of the animations are working in the frame. I tried just switching root to _parent and this is not working. Any suggestions?

mikenaman
10-02-2007, 12:12 PM
Hi

You can do a quick fix by doing...

myMovieClip._lockroot = true;

myMovieClip being the moveClip the swf is loaded in to. This will lock all _root calls of the swf file in myMovieClip to the _root of the loaded file.

(that's terrible english, but it makes sence in my head!)

BUT THAT'S A COP OUT...

The _parent part should work so it sounds like you could have a scoping issue. If the functions exist in the same location as the movieClips you trying to access via _root["pic"+prevNum], then instead you could write this["pic"+prevNum].

If the mc's your trying to access do not exist in the same location as your functions, then may I sugest changing your functions to something like this...

function animateFrame(whichMc:MovieClip ,num:Number, xPosPic1:Number, yPosPic1:Number) {
var prevNum = num-1;
//fase last out
//--ALSO YOU DO NOT NEED THE var alphaP1:Tween = UNLESS YOU
//--NEED TO REFFERENCE THE TWEEN LATER ON IN YOU CODE
new Tween(whichMc, "_alpha", None.easeOut, 100, 0, 1, true);
}

The addition of whichMc means you can call your function from anywhere, to act on movieClips in any location.

To call the function...

animateFrame(this["pic"+(num-1)],2, 120, 500)