PDA

View Full Version : How to restrict a rollOver when MC._currentframe > 1?


Dave At ADC
08-19-2005, 04:42 PM
Alrighty - This is the problem. I have these as functions:

function expandMenuTwo() {
if (menuTwoExpanding == false) {
menuTwoExpanding = true;
MenuTwo.gotoAndPlay("Expand");
}
}

function retractMenuTwo() {
if (menuTwoExpanding == true) {
menuTwoExpanding = false;
menuTwoGotoFrame = MenuTwo._totalframes - MenuTwo._currentframe;
trace(menuTwoGotoFrame + " -- " + MenuTwo._totalframes + " -- " + MenuTwo._currentframe);
if (menuTwoGotoFrame >= 40) {
MenuTwo.gotoAndPlay(menuTwoGotoFrame);
} else {
menuTwoGotoFrame = MenuTwo._currentframe - 40;
MenuTwo.gotoAndPlay(menuTwoGotoFrame);
}
retractMenuTwo;
}
}


So, what that is supposed to do, which it does, is it starts to play my movieclip forward on the timeline to frame 4, where it is told to stop... however, if the user mouses off the movieclip it simulates a reversal jumping to the myMC._currentframe + 40 (Since the total MC is 80 frames long: 40 Forward, 40 Back)... but, when the frames 41 --> 81 are playing, if the user jumps back on the MC, it jumps to frame one but doesn't register that rollOver. Attached is an example of what I mean. Mouse over the button on the right to see what I am talking about.

So, how would I restrict a rollOver to only happen when the movieClip is on frame 1? Also if you can, check out my buttons animated within the Movie Clip. Why dont they work?

nyghtrunner
08-19-2005, 04:57 PM
function expandMenuTwo() {
//Add the _currentframe to check to see if the currentframe is the first. Something
//similar can be done to restrict the closing
if (menuTwoExpanding == false && MenuTwo._currentframe == 1) {
menuTwoExpanding = true;
MenuTwo.gotoAndPlay("Expand");
}
}

Dave At ADC
08-19-2005, 05:03 PM
Very good nyghtrunner... but this bring one last question to mind:

Now lets say I am restricting the user the ability to openup the menu if they rollOver... but what if they hold their mouse there? Does the hitTest() work in this situation? I guess if I could detect the _xmouse and _ymouse when the movieclip is fully retracted, then I could fire the command to expand it again. This would eliminate the confusion on like, "How do I get this to open up again!?" since some people wouldn't think to rollOver again. Sadly, things have to be fool-proof.

I appreciate your help. Thanks ^_^

Dave At ADC
08-19-2005, 06:13 PM
Wow. Can anyone help me figure this out? I need to get my submenu buttons working. >_< I attached the file above. Perhaps you can find a bug? Do I need to use a hitTest(), should I do something like detect the mouse if it is within the boundries of the button... or is there a simpler way like make the buttons work like buttons... They are buttons!? UGH!

nyghtrunner
08-19-2005, 06:20 PM
hmmm.... One thing you "COULD" do, would be to use a setInterval to call a function... And then make it play backwards or forwards. I suppose you could use an onEnterFrame to do this too, if you don't want to mess with the setInterval...

It sould be something like this:


var expand;
var speed = 1;

MenuTwo.onEnterFrame = function() {
if (expand == 0) {
this.gotoAndStop(this._currentframe + speed)
if (this._currentframe >= 40) {
this._currentframe = 40;
}
} else if (expand == 1) {
this.gotoAndStop(this._currentframe - speed)
if (this._currentframe <= 1) {
this._currentframe = 1;
}
}
}

MenuTwo.onRollOver = function() {
expand = 1;
}

MenuTwo.onRollOut = function() {
expand = 0;
}

MenuTwo.onDragOut = function() {
expand = 0;
}



This is a way to do it, but I think it will inherently be pretty buggy. A better way to do it would be to bypass the timeline completely, and do everything with ActionScript. It's hard to make things foolproof elsewise, as they tend to start getting buggy. I might be able to think of a better way, but I haven't really thought in these terms in such a long time that I'm not used to this anymore. If I think of something tho, I'll post it.

If you understand Dynamic attachment, for loops, and Arrays, let me know, and I'll post a much cleaner solution for you.

S

nyghtrunner
08-19-2005, 06:38 PM
sry, had to edit it, I forgot a bracket

Dave At ADC
08-19-2005, 06:54 PM
Nope. I dont understand "Dynamic attachment, for loops, and Arrays"... even tho I do understand loops and arrays (Arrays I haven't worked with in an OO Language) but I have read the stuff and I understand the logic

Also, have you checked out those buttons? THey're in the movieclips, so I figure I would be able to hit them... oddly enough, I cant O.o Any reasons why?

Thanks again for your time and responses. ^_^

flashead
08-19-2005, 07:08 PM
Also, have you checked out those buttons? THey're in the movieclips, so I figure I would be able to hit them... oddly enough, I cant O.o Any reasons why?
This is because you have nested buttons. Flash doesn't doesn't like that. use a hitTest to get your menu to drop down and reserve your rollOver's for the sub-menu buttons.

nyghtrunner
08-19-2005, 07:15 PM
He's right, Flash doesn't like anything nested in a movie clip that has extra functionality. And a hit test with the xmouse/ymouse might be the best option...

This is Y you attach everything Dynamically. You could keep them separate instances with separate functions. As it is, Another option would be to cross reference things. IE - Have the animation with the nested buttons in one movie clip, and the rollover a separate one. Then just change a few of the names. And make SURE that the one with the buttons is on a layer UNDER the one you rollover.

Something like this should work:



var expand;
var speed = 1;

mc_W_Btns_mc.onEnterFrame = function() {
if (expand == 0) {
this.gotoAndStop(this._currentframe + speed)
if (this._currentframe >= 40) {
this._currentframe = 40;
}
} else if (expand == 1) {
this.gotoAndStop(this._currentframe - speed)
if (this._currentframe <= 1) {
this._currentframe = 1;
}
}
}

MenuTwo.onRollOver = function() {
expand = 1;
}

MenuTwo.onRollOut = function() {
expand = 0;
}

MenuTwo.onDragOut = function() {
expand = 0;
}



Actually, so long as that works, that might be the quickest fix. Hit Tests have a bad habit of being slightly inaccurate.

Dave At ADC
08-19-2005, 07:48 PM
I apologize, but I dont quite understand what you mean:

This is Y you attach everything Dynamically. You could keep them separate instances with separate functions.

Do you mean if there is code for a button, attach it to the button and not create functions? I appreciate all your help, but I'm headed home now. I'll be able to check the forums in an hour or so. Thanks again for your help!

nyghtrunner
08-19-2005, 08:28 PM
No, not at all. Perhaps I should have said behaviors, not functions. It is better to write a function and then call it than to embed it. Largely because embedding things can only be read so far, which is a flash quirk, as far as I know.

I meant simply that if you attach things dynamically, and use code only to manipulate things, it gives you COMPLETE control over everything, whereas it is inevitable that you will run into more flash quirks elsewise.

For this, just remember that if you write functions or code for a movie or a button, and then those instances are placed inside another movie or button with more functionality assigned to that, Flash will only look at the first instances with functionality and assigned behaviours, and disregard everything else there. :(

I hope this helps... It's not really making too much sense even as I'm saying it...