Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : reversing a clip on a button click


sooz_e
6/14/2006 7:48:08 PM
Hi,

What I want to happen here is that the page go through its load animation
backwards (to unload the page) when the user clicks a button on the nav menu.

It kinda worked once or twice, but in the if {} suddenly jumped to main time
line from the page clip and only a couple frames worth were reversed.

a trace() after "_parent.gotoAndStop(70)" shows the _parent._currentframe as
70.
breakpoints while debugging don't seem to get close to the if{} now? It is
always skipping from " _parent.onEnterFrame = function() {" directly to "
_root.gotoAndPlay(_global.pageToPlay);" Breakpoints on and inside the if are
not hit?

Can anyone help?

Sue

on (release) {
_global.pageToPlay = 2;//main page
_parent.gotoAndStop(70);
_parent.onEnterFrame = function() {
if (_parent._currentframe > 1) {
this.prevFrame();
}
};
_root.gotoAndPlay(_global.pageToPlay);
}
kglad
6/14/2006 8:35:21 PM
try:


on (release) {
_global.pageToPlay = 2;//main page
_parent.gotoAndStop(70);
_parent.onEnterFrame = function() {
if (this._currentframe > 1) {
this.prevFrame();
}
};
_root.gotoAndPlay(_global.pageToPlay);
}
sooz_e
6/14/2006 11:45:30 PM
Hmmm...I see how I wouldn't want that function attached to onEnterFrame outside
this if{}. Thank you : )

This didn't fix whatever the trouble is though? The breakpoint stops at the
_parent.onEnterFrame, but even a trace before the if{} doesn't print to the
output window? It is as if the onEnterFrame has already happened and so the
function doesn't get called.

Thanks for taking a look,

Sue
kglad
6/14/2006 11:52:29 PM
_root and _parent in your onRelease handler are differenet, aren't they?
what's the output window show if you use the following:



on (release) {
trace("a "+_parent+" "+_root);
_global.pageToPlay = 2;//main page
_parent.gotoAndStop(70);
_parent.onEnterFrame = function() {
trace("b "+this+" "+this._currentframe);
if (this._currentframe > 1) {
this.prevFrame();
} else {
delete this.onEnterFrame;
}
};
_root.gotoAndPlay(_global.pageToPlay);
}
sooz_e
6/15/2006 3:47:30 AM
Yes,

Root and parent are different, and parent is different depending on which
instance of the websites basic page the navigation button is clicked on.

a _level0.servPage _level0 //mainPage button clicked on the servicePage
instance of pageTemplate_mc
a _level0.mainPage _level0 //mainPage button clicked on the mainPage instance
of pageTemplate_mc

b, inside the function, never gets hit.

I was using _parent instead of this inside the function for awhile. In some
rendition of the code a few frames played backward, but on the root timeline
rather than on the page clip time line. Does the reference change after the
gotoAndStop? Or does it stay the same as long as the code is executing from
button instance onRelease?

Thanx again for helping out :)

kglad
6/15/2006 4:02:59 AM
what happens to _parent on its frame 70?:

p.s. movieclip references within the button handler don't change with frame
changes, but do change within other handlers like your enterFrame handler.


on (release) {
trace("a "+_parent);
_global.pageToPlay = 2;//main page
_parent.gotoAndStop(70);
trace("b "+_parent);
_parent.onEnterFrame = function() {
trace("c "+this+" "+this._currentframe);
if (this._currentframe > 1) {
this.prevFrame();
} else {
delete this.onEnterFrame;
}
};
_root.gotoAndPlay(_global.pageToPlay);
}
sooz_e
6/15/2006 4:24:12 AM
There are about 84 frames in _parent. It is about 70 frames of rectangles,
logos, and buttons flying into position. A few frames after 70 I use
attachMovie and a switch to select the correct content layout, and assign the
correct dynamic text to that layout. There are some frames w/ script in them
after 70. In the rendition of code that was sort of working (incorrectly), I
got the idea it might not be a good idea to reverse to the frame with that
script in it. Beyond that 70 was a random choice.

re: p.s. ---so it should be this inside the onEnterFrame function and _parent
outside the function?

Thanx,

Sue
sooz_e
6/15/2006 2:44:16 PM
Hey,

I got this to work!

Couldn't have done it w/o the delete clause in the if/else, so thanks again
for your help!

Playing in reverse was slower than forward, so I moved the code to frame 35
from 70 in order to shorten the reverse.
In case anyone else is struggling with this or cares to, the code is attached.

My code is getting pretty dispersed throughout varioous clips' timelines.
Could code like this even be managed from the main timeline frame 2?

Sue

FRAME 2 OF MAIN TIME LINE
-----------------------------------------------
_global.pageToPlay;//to hold the frame number on the main timeline of the page
to play
_global.reversePlay = false;//flag to indicate direction to play frames
stop();//stop the scene after the main page loads


ON EACH NAV MENU BUTTON
-----------------------------------------------
on (release) {
_global.pageToPlay = 2;//main page
_global.reversePlay = true;//flag to indicate direction to play frames
_parent.gotoAndPlay(35);
}


FRAME 35 OF pageTemplate_mc
-----------------------------------------------
/*to make loaded page appear to unload by playing in reverse if
_global.reversePlay is set to true. _global.reversePlay is
initialized to false in frame 2 and set to true in the button scripts
of the nav menu.
*/
this.onEnterFrame = function() {
if (_global.reversePlay == true){
if (this._currentframe > 1) {
this.prevFrame();
} else {
_global.reversePlay = false;
_root.gotoAndPlay(_global.pageToPlay);
}
}else {
delete this.onEnterFrame;
}
};
AddThis Social Bookmark Button