Skip to main content
February 3, 2009
Question

tween and getting instance names problems

  • February 3, 2009
  • 4 replies
  • 467 views
Hi, iv got these buttons animated using the inbuilt tween function and am coding them like this:

function navOver(e:MouseEvent):void {
var page = MovieClip(e.currentTarget).buttonThumb;
var myTween16:Tween = new Tween(page, "y", Regular.easeOut, 0, -25, 0.35, true);
}

function navOut(e:MouseEvent):void {
var page = MovieClip(e.currentTarget).buttonThumb;
var myTween17:Tween = new Tween(page, "y", Regular.easeOut, -25, 0, 0.35, true);
}

function navClick(e:MouseEvent):void {
var page = MovieClip(e.currentTarget).buttonThumb;
page.y = 0;
}

button.addEventListener(MouseEvent.ROLL_OVER, navOver);
button.addEventListener(MouseEvent.ROLL_OUT, navOut);
button.addEventListener(MouseEvent.MOUSE_DOWN, navClick);


but if i click on the button before the animation has finished it ignores the page.y = 0; code and does nothing. how can i fix this?

also im trying to get the instance name of a mc called "home" using this code:
MovieClip(e.currentTarget) wich gives me the result [object button_1]
and
MovieClip(e.currentTarget).instanceName returns undefined
neather of which are the instance name.
i cant hardcode the function because its used on lots of different mcs throughtout the flash file

thanks
This topic has been closed for replies.

4 replies

February 4, 2009
yeah that worked. thanks so much fro your help! i just keep struggling with the as3 syntax, but il get there in the end!
clbeech
Inspiring
February 3, 2009
right - my bad - that will return a 'String' data type - so that wont work to cast it as a MC - so something more like:

var instanceName:String = e.currentTarget.name;

then use the 'name' however you need to. however, if you are looking for a direct reference to the instance, your first call above will give you that:

e.currentTarget.x = X;

you can access the properties and methods directly in this manner. you may need to cast it though - depends on the scope as in:

MovieClip(e.currentTarget).x = X;
February 3, 2009
cheers that worked for the tweening problem.

but when trying to assign the instance name to a variable ( using var newVar; to initiate the variable so not setting its type) i get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert "page2" to flash.display.MovieClip.
clbeech
Inspiring
February 3, 2009
if you want to send the 'page' back to the 0 position, you might be better off declaring the tweens outside the method, in this way you can control them in 'other' methods that aren't local to where the assignment is made, for instance:
var myTween17:Tween;

then in the handler navOut, just 'assign' the tween:
myTween17 = new Tween( .. );

then in the navClick method you could call:
myTween17.stop();
myTween17.rewind();

and that should reset the clips position to 0

for your other question use:
MovieClip(e.currentTarget.name);