Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onRelease function not working 1

Status
Not open for further replies.

NIA2

Technical User
Aug 30, 2006
137
AU
Hi everyone,

I have the following code on frame 1 of the main timeline:

this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
trace("button pressed");
oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 0, garmentSlides_mc, 5);
new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
}

When I test the movie I get the hand cursor appear when I rollover the button indicating that it is in fact a button but when I press and release it, none of the code works. I added the trace statement to see what was going on but again when testing it the output window doesn't appear.

Can someone tell me if there's something wrong with the code? The following is the entire code on frame 1 of the main timeline.

Appreciate any help offered.



CODE

//-----------Initialization---------\\
import mx.transitions.Tween;
this.categoryIndex_mc._alpha = 0;
this.garmentSlides_mc._alpha = 0;
//-----------------------------------\\

//-----------Introductory animation plays---------\\

intro_mc.onEnterFrame = function () {
this.play();
delete intro_mc.onEnterFrame;
}
//-----------------------------------\\


//-----------Category list fades in---------\\

var oIntervalIDs:Object = new Object();

function fadeMovieClip (mClip:MovieClip, nRate:Number):Void {
if(mClip._alpha >= 0 && mClip._alpha < 100) {
var nAlpha:Number = mClip._alpha;
mClip._alpha = nAlpha + nRate;
updateAfterEvent();
}
else {
clearInterval(oIntervalIDs[mClip._name]);
}
}

oIntervalIDs[categoryIndex_mc._name] = setInterval(fadeMovieClip, 100, categoryIndex_mc, 5);

categoryIndex_mc.onEnterFrame = function () {
if(categoryIndex_mc._alpha > 95) {
this.indexBack_mc.gotoAndPlay("chooseText");
delete categoryIndex_mc.onEnterFrame;
}
}

//-----------------------------------\\


//-----------Slideshow fades in, category index slides out, playhead jumps "back to index" frame ---------\\

cat_btn.onRelease = function ():Void {
oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 100, garmentSlides_mc, 5);
new Tween(categoryIndex_mc, "_y", null, 107, 412, 3, false);
categoryIndex_mc.indexBack_mc.gotoAndStop("backToIndex");
}
//-----------------------------------\\


//-----------Slideshow fades out, category index slides in, playhead jumps "please choose category" frame---------\\

this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
trace("button pressed");
oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 0, garmentSlides_mc, 5);
new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
}

//-----------------------------------\\
 
Is the backToIndex_btn present on stage on the first frame of your movie, or does it only appear down the timeline somewhere?
If so, that's probably your problem... The button needs to be present on stage, on the frame you're assigning a handler to it...
If not, then you might have button handlers on the clip(s) in which the button is nested, and then those will simply override any nested symbols's actions...

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Thanks for the reply,

backToIndex_btn is nested within indexBack_mc which in turn is nested within categoryIndex_mc. There's only 1 frame on the main timeline and it has 3 layers. Each of the layers contain a movieclip - intro_mc, categoryIndex_mc and garmentSlides_mc. intro_mc plays first with the first block of code listed above, then categoryIndex_mc fades in. When a button is pressed, garmentSlides_mc fades in and categoryIndex_mc slides down but still remains partially on the stage. When categoryIndex_mc reaches it's position, the playhead jumps to the last frame in indexBack_mc which is where backToIndex_btn button is.

So when you asked is backToIndex_btn present on the stage - does my description indicate that it is? I mean it must be present if the button is active with a hotspot right? I know it's nested but it's still on the stage on frame 1, since there's only 1 frame on the main timeline right?

I'm confusing myself a bit, but can you help out some more?
 
Wait a second...
You're saying... "the playhead jumps to the last frame in indexBack_mc which is where backToIndex_btn button is"

So isn't that saying that the button is not present on stage on the main timeline's first frame?

Try adding your script on the last frame of the indexBack_mc (where the button is), to see if it doesn't work then.

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Thanks - I've emailed the file if you'd take a look?
 
Yeah... The button isn't present on the main timeline's first frame, since it only appears on frame 49 of the indexBack_mc, which is stopped on it's own frame 1. So you can't target the button from the main timeline in this manner...

If I change your frame 49 script to this...
Code:
stop();
import mx.transitions.Tween;
backToIndex_btn.onRelease = function ():Void {
    trace("button pressed");
    //oIntervalIDs[_level0.garmentSlides_mc._name] = setInterval(_level0.fadeMovieClip, 0, _level0.garmentSlides_mc, 5);
    new Tween(_level0.categoryIndex_mc, "_y", null, 412, 107, 3, false);
	this._parent.gotoAndPlay("chooseText");
}

It all works, except the setInterval and fadeMovieClip bits (line that I commented out...), because I've failed up until now, to properly target them...

Maybe you can't work it out... Will have another try later on, if you can't get it working either...

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Thanks for the code - it seems to have fixed the problem except for the setInterval targetting as you say.

I'm not able to target it correctly either - do you have any further suggestions to solve this part?
 
After testing it further, I realized that it was mainly not working because you only have a fade in script and no fade out script... I've added a similar fade out script but I'm still having troubles with it... Will post it if I can find a few minutes to work on it more...

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
I've ended up putting the following code on the frame where the button lives:

stop();

import mx.transitions.Tween;

backToIndex_btn.onRelease = function ():Void {
oIntervalIDs[_level0.garmentSlides_mc._name] = setInterval(_level0.fadeMovieClip, 50, _level0.garmentSlides_mc, -1);
new Tween(_level0.categoryIndex_mc, "_y", null, 412, 107, 3, false);
this._parent.gotoAndPlay("chooseText");
}

The fadeMovieClip function allows you to fade a movieclip up or down by having 1 for up or -1 for down. The 50 is the rate at which it fades, ie. faster or slower.

When I test the code though, garmentSlides_mc fades out but at a really, really slow pace. I can hear my computer's processor speed up and the whole computer slows down. I don't know what the code is doing to eat up all the memory - it's really strange.

Do you know what could be causing this?
 
No the function is still as follows:

var oIntervalIDs:Object = new Object();

function fadeMovieClip (mClip:MovieClip, nRate:Number):Void {
if(mClip._alpha >= 0 && mClip._alpha < 100) {
var nAlpha:Number = mClip._alpha;
mClip._alpha = nAlpha + nRate;
updateAfterEvent();
}
else {
clearInterval(oIntervalIDs[mClip._name]);
}
}

oIntervalIDs[categoryIndex_mc._name] = setInterval(fadeMovieClip, 10, categoryIndex_mc, 1);

Any clues?
 
Thanks so much for the revised code - it works perfectly now.

Really appreciate all the time you put in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top