PDA

View Full Version : [Q] Accessing the movieClip from the onMotionFinished handler...


CyanBlue
11-06-2005, 04:41 PM
Howdy... :)

Got a question...
I've got this script...
var p_mc = this.attachMovie("MC_Pause", "pause_mc", 999999, {_x:400, _y:300});
p_mc._alpha = 0;

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

var tween_handler:Object = new Tween(p_mc, "_alpha", Strong.easeIn, 0, 50, 1, true);
tween_handler.onMotionFinished = function()
{
trace("onMotionFinished triggered this = " + this);
for (var i in this)
{
trace("\t" + i + " : " + this[i] + " : " + typeof(this[i]));
}
// this[obj].removeMovieClip();
// removeMovieClip(this[obj]);
p_mc.removeMovieClip();
trace("_level0.pause_mc.getDepth() = " + _level0.pause_mc.getDepth());
_level0.pause_mc.removeMovieClip();
trace("_level0.pause_mc.getDepth() = " + _level0.pause_mc.getDepth());
}
The output from that script is...
onMotionFinished triggered this = [Tween]
prevTime : 0.968 : number
onMotionFinished : [type Function] : function
isPlaying : false : boolean
_startTime : 25 : number
_time : 1 : number
broadcastMessage : [type Function] : function
_listeners : [Tween] : object
change : 50 : number
func : [type Function] : function
useSeconds : true : boolean
_duration : 1 : number
_pos : 50 : number
prevPos : 42.4958764662784 : number
begin : 0 : number
prop : _alpha : string
obj : _level0.pause_mc : movieclip
_level0.pause_mc.getDepth() = undefined
_level0.pause_mc.getDepth() = undefined
As you can see we have 'obj' in the Tween object but my attempt to access that is not working...
// this[obj].removeMovieClip(); // NOPE
// removeMovieClip(this[obj]); // NOPE
p_mc.removeMovieClip();
Can anybody explain why I am not able to access the _level0.pause_mc when I say 'this[obj]'???

Thanks... :)

amen0
11-06-2005, 05:38 PM
obj is undefined
try like this
this["obj"].removeMovieClip();

Flash Gordon
11-06-2005, 05:50 PM
Hey CyanBlue,

I can't see why it doesn't get your movieclip. I have always used this syntax and haven't had any problems with it. Sorry it doesn't fix your problem, but just a different perspective (basically from the tut).


function tween(mc, prop, easeType, begin, end, time, goOn) {
//easeType = mx.transitions.easing.Bounce.easeOut;
//var begin = 20;
//var end = 380;
//var time = .5;
//var mc = ball_mc;
tweenMove = new mx.transitions.Tween(mc, prop, easeType, begin, end, time, true);
if(goOn) {
tweenMovie.onMotionFinished = function() {
//stuff
}
}
}
_root.tween(_root.container_mc, "_x", mx.transitions.easing.Strong.easeOut, 0, 75, 2.5, true);


Sorry I couldn't be more help, but maybe that gives you an idea what might be wrong with yours.

Xeef
11-06-2005, 07:55 PM
// this[obj].removeMovieClip(); // NOPE
// removeMovieClip(this[obj]); // NOPE


:D :D :D

CyanBlue you need More COFFE !!!

obj : _level0.pause_mc : movieclip



this["obj"].removeMovieClip(); or this.obj.removeMovieClip();

removeMovieClip(this["obj"]); or removeMovieClip(this.obj);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!

CyanBlue
11-06-2005, 10:17 PM
Hm... That's very interesting...

Yes, any of these works...
this.obj.removeMovieClip();
removeMovieClip(this.obj);
So, if I say this[obj], Flash has no idea but if I say this.obj, Flash understands???

That does not really make sense to be because both should be working the same like this case...
this.createEmptyMovieClip("test_mc", 100);
this.test_mc._x = 100;
trace(typeof(test_mc) + " : " + this.test_mc._x); // movieclip : 100
this["test_mc"]._x = 200;
trace(typeof("test_mc") + " : " + this["test_mc"]._x); // string : 200
this[test_mc]._x = 300;
trace(typeof(test_mc) + " : " + this[test_mc]._x); // movieclip : 300
This is not really making much sense to me... What I am saying is that if I use '[' and ']', it should reference the path correctly as long as 'this' refers to the '_level0' but that is not happening here...
Can anybody explain to me why this is happening??? :(

Thanks, guys... :)

amen0
11-06-2005, 11:12 PM
this.createEmptyMovieClip("test_mc", 100);
this.test_mc._x = 100;
trace(test_mc + " : " + this.test_mc._x); // _level0.test_mc : 100
this["test_mc"]._x = 200;
trace(this["test_mc"] + " : " + this["test_mc"]._x); // _level0.test_mc : 200
this[test_mc]._x = 300;
trace(this[test_mc] + " : " + this[test_mc]._x); // _level0 : 300
trace(this + " : " + this._x); // _level0 : 300

it seems flash ignore this[test_mc] and take is as this only !!!

CyanBlue
11-06-2005, 11:35 PM
Now I am confused... :(

Xeef
11-06-2005, 11:59 PM
Hmmmmm

So, if I say this[obj], Flash has no idea but if I say this.obj, Flash understands???

CB

did you drunk to much ???

[] --> object/array access

object -->
_root[Bla] //Bla HAVE to by a STRING !!!! AND NOT an Object !!!!

this.obj vs. this[obj] either is obj a STRING or an OBJECT
either the first or the second will work !


Hmmmmm

somebody highjacked CB's name !!!

CyanBlue
11-07-2005, 12:26 AM
Hm... I thought that 'Bla' can be a movieClip as well??? Arg... My brain hurts... :(