PDA

View Full Version : gotoAndPlay() doesn't work from upper level???


simobk
06-15-2005, 04:15 PM
Hi,

This is some really weird problem... It's been an hour I am trying to figure it out, but I don't know why, it feels like it's something really stupid that I can't find.

It's a simple gotoAndPlay :
_root.mainContentMC.portfolio.gotoAndPlay(2);

This works ONLY if I place the code in _root.mainContentMC.portfolio or a deeper level. It doesn't work on _root, _root.mainContentMC or any other.

What happens is it does go to the frame, but doesn't play from there... As if it did a gotoAndStop();

- Tried naming the frame and addressing the frame's name, doesn't work.
- Tried absolute and relative addressing, doesn't work.
- Tried changing the MC's instance name, doesn't work.
- Tried sending other instructions (gotoAndStop, _alpha...), IT WORKS...

I really have no idea on what's causing this...

Thanks for any help,

Simo

--------------

EDIT :

Actually, I made some tests, and the gotoAndPlay works if I attach the code to a button, but not if I attach it to a frame.

I attached here a stripped version of the FLA where I removed everything but the main parts.

On frame1 of _root, I placed :
_root.mainContentMC.portfolio.gotoAndPlay(2);

And on the button on the _root level, I placed :
on(release)
{
_root.mainContentMC.portfolio.gotoAndPlay(2);
}

The code on the button does go and play, but the code on the frame does just a gotoAndStop(2)

???

Any idea?

Slowburn
06-15-2005, 05:49 PM
wait one frame before executing the gotoAndPlay() function in your main timeline. The reason for this is so that your flash movie has enough time to load the internal content before executing the commands. (use these free frames to preload your content)

Frame2:

_root.mainContentMC.portfolio.gotoAndPlay(2);
stop();

simobk
06-15-2005, 06:36 PM
huuh... It doesn't work... :( I mean, it does work on the stripped version that I have attached, but not on the real version... The thing is, on the real version, it is not called by a frame, but by a button that calls a function :

The function :
function bringToFront(item)
{
switch (item)
{
case "cv":
target = _root.mainContentMC.curriculum;
break;
case "portfolio":
target = _root.mainContentMC.portfolio;
if (_root.inFront != "portfolio")
{
_root.mainContentMC.portfolio.gotoAndPlay(2);
}
break;
case "contact":
target = _root.mainContentMC.contact;
if (_root.inFront != "contact")
{
_root.mainContentMC.contact.envelopeMC.envelopeCov erAnimMC.gotoAndPlay(2);
}
break;
}

// Bring item to front and adjust variable
target.swapDepths(1000);
_root.inFront=item;

// Close everything else
_root.closeAll();
}

The button
// Display and hide Info
on(rollOver) { _root.showInfo("Glissez et déposez afin de déplacer le Portfolio"); }
on(rollOut) { _root.hideInfo(); }
on(press) { this.startDrag(); }
on(release)
{
this.stopDrag();
_root.bringToFront("portfolio");
}

How comes it needs to preload the content? I mean, I have a preloader for the whole movie, and I use the exact same code running perfect on other MC's...

It works good for all others EXCEPT this one...

Any idea?

Thanks,

Simo

simobk
06-16-2005, 05:01 PM
Problem solved :)

Actually, by changing the dragged element to the parent, it worked... Don't ask me why, I have absolutely no idea :)

// Display and hide Info
on(rollOver) { _root.showInfo("Glissez et déposez afin de déplacer le Portfolio"); }
on(rollOut) { _root.hideInfo(); }
on(press) { this._parent.startDrag(); }
on(release)
{
this._parent.stopDrag();
_root.bringToFront("portfolio");
}

Thanks for the help ;)

Simo

bobocel
07-20-2007, 01:15 PM
It must be something inside Flash. I had the same problem.. so I did this:

mcName.gotoAndStop(2);


and inside mcName, on frame 2, I wrote:
play();

simobk
07-20-2007, 01:51 PM
Wow... Thanks for trying to help bobocel... But this thread is... more than 2 years old :eek:

I didnt even remember I had this problem :D

Thanks anyways,

Simo

Token
11-10-2008, 01:39 AM
Oh, man! This problem has been freaking me out for the whole day, and at last, at 5.30 am, I've found this thread!.. Thank you, guys!!

bobocel, your solution is great. I remember I used it a couple of times, it really seems like a bug or something...

envoltorio
09-03-2009, 12:05 AM
oh bobocel! you were sent form the past to save me! thank you more than 2 years later :)

inkydgh
01-14-2010, 04:19 AM
It must be something inside Flash. I had the same problem.. so I did this:

mcName.gotoAndStop(2);


and inside mcName, on frame 2, I wrote:
play();


Doesn't work for me. And my script itself is quite simple...

this.onEnterFrame = function()


{

Main.gotoAndPlay(1);
if (Key.isDown(Key.RIGHT))
{
Main._x += 20;
Main.gotoAndPlay(4);
if (Main.hitTest(400, Main._y, true))
{
Main._x -= 40;
}


}else if (Key.isDown(Key.LEFT))
{
Main._x -= 20;
Main.gotoAndPlay(7);
if (Main.hitTest(0, Main._y, true))
{
Main._x += 40;
}
if (Main.hitTest(400, Main._y, true))
{
Main._x -= 20;
}
It doesn't play, whatever I do...
gotoAndPlay(4) works perfectly, when I hit a key, but I want it to go back to frame one when key is released.

I also have a problem with hitTest, it doesn't work.


Help?