Help with advanced Flash buttons!

Started by BaconXBits, April 4, 2009 02:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BaconXBits

So I'm making a new movie interface for all of my future movies, and I'm having trouble on the bottom ones in particular.  The subtitles button (top left) works well, but I can't quite say the same about the movie control bar (bottom left)



You can see what the movie control animations are SUPPOSED to look like by hovering over a non-button part of the hitbox (eg far right).  I haven't bothered doing the LMH buttons yet because I'm probably doing something horribly wrong.

Summary of what I need help on:

SUBTITLES:
-Making the button not repeat the "over" frame upon being clicked.  This solution would probably be applied to the movie control bar as well.

MOVIE CONTROL BAR:
-Preventing the main button's "over" animation from repeating upon hovering or clicking on the smaller buttons.

NOTES:
-I haven't used any ActionScript except for stop(); at the end of EVERY "over" movie clip.
-As far as I know, I haven't made any retarded mistakes such as neglecting to put stop(); at the dne of a movie clip.

Also here's a picture of my library so you get a slightly decent image of what's going on in my intricate clusterfuck of a button (the MC stands for "Movie Control," not "Movie Clip"):



For each button, I basically just have it glow (non-animated) and have a graphic describing the button's function tween upwards (Prev. Scene, Play, etc.), stopped by a stop();.  The only time I convert something into an actual symbol is if I need to animate within it (MC) or apply a filter (also MC).  The button descriptions are grouped vectors (CTRL+G'd).

Any solutions or alternatives that would achieve a similar effect would be appreciated!

If anyone wants me to send them the .fla hit me up on MSN or I can upload it.

RobHalford

I'm out ot town for the weekend, but you can PM it to me now and I should be able to fix it during next week.

QuoteBut nevvgrounds is totally different from 4chan. We are a different set of people.
Quote<+ukinojoe> kirbopher is a pile of jackets
<+ukinojoe> if you remove them all
<+ukinojoe> all thats left is a dead rat

Joelasticot

Using a many buttons in Flash is bound to go wrong at some point, so, to resolve your issue I suggest you use some Movie Clips & use a bit of code

Here's how :

For your two menus, subtitles and movie control, you will have 2 separate movie clips. These movie clips will hold, on one layer, the animations, and on another layer, an invisible movie clip that will be used to test if the mouse is in the "over" region. I'll walk you through making the subs movie clip but it's pretty much the same for the movie control one

First, make a new movie clip. On layer 1, frame 1, put the "out" animation of the subs menu, and on frame 2, the "in" animation. They both must be within their own movie clips with a stop(); on the final frame. Now, make a new layer, and draw a box over your menu (and within the flash stage) that will be the area that triggers the menu. Convert it to a movie clip and give it the instance name of "hit". MCs don't register mouse clicks by default so it won't interfere with your buttons, even if it's on top of them.

Now, make a third and final layer for AS, and put this code on frame 1 :

hit._visible = false;

onEnterFrame = function():Void
{
if(hit.hitTest(_root._xmouse, _root._ymouse))
//note : if you want to use a non-rectangular hit zone, add ", true" after" _root._ymouse", within the parentheses
{
nextFrame();
}
else
{
prevFrame();
}
}

What this does is make the hit zone invisible (obviously), then, each frame, it'll check if it touches the mouse using a hitTest, and will go forward (show menu) if that is the case, or backward (hide menu) if it doesn't. After this, your control buttons should cause no problems. Let me know if you encounter any issues

BaconXBits

#3
Thank you very much, you're a hero!  I didn't even know you could make buttons out of movie clips and ActionScript.  I'll try to work things out to see if I can get everything working properly.

Edit: See below.

RobHalford

K, so I'm back.

If you want it in AS3, I'm all ears.

QuoteBut nevvgrounds is totally different from 4chan. We are a different set of people.
Quote<+ukinojoe> kirbopher is a pile of jackets
<+ukinojoe> if you remove them all
<+ukinojoe> all thats left is a dead rat

BaconXBits

#5
Big fat update.

So here's an update on what's working:
-The Subtitles button works flawlessly, tested and everything.
-The ANIMATIONS on the movie control menu (but the buttons themselves don't actually work).

What's left to be resolved (in order of urgency):
-Making the buttons actually serve their intended function.  For some reason, the quality buttons work perfectly, but all of the other ones just repeat the "over" animation of the movie control menu (except for the "Pause" button, for reasons I do not understand).  This confuses me because they're made exactly the same, with the same layers, frame setup, and same everything.  I tried doing the movie clip button inside a movie clip thing for the "Previous Scene" button (the method Joelasticot gave me), and it has the same result as the other buttons.  My best guess is that the buttons don't work because they think that I want them to perform their actions within the movie clip they are in, and not in the main timeline.  Any code that would make those buttons apply to the main timeline would basically fix my problem.
-Is there any way to not have the movie control/subtitles buttons play their "up" animation at the beginning of a scene?  Currently I have the alpha set to 0% at the beginning of each scene, and then to 100% on the frame that the button animation ends.  I see this as a minor problem, as the buttons would be unavailable/invisible for 11 frames.
-How would I go about displaying the status of the subtitles (on/off) for a short time before fading?  This isn't necessary but it'd be nice to have.

Here's an updated preview of my buttons:

Note that the "Previous Scene" button was made differently from all of the other ones (using a repeating method of the way I made the subtitles button).  Also take my word for it when I say that the former 5 buttons don't work, as there are no scenes or frames to test them on in this swf.

And here's a .fla if it helps.

Quote from: Rob HalfordK, so I'm back.

If you want it in AS3, I'm all ears.
I'd rather not; I prefer to have everything in AS2 since I know literally nothing about how AS3 works.

Joelasticot

As you guessed, the problem with the buttons not working was that the actions were "sent" to the nearest timeline, which is the timeline of the movie clip in which they are nested. To resolve this issue, we add the prefix "_root." to actions we want to be executed on the main timeline. However, this causes scene actions not to work because using _root. makes flash treat the timeline as a movie clip, and movie clips don't have scenes. I've created a simple function that will do the scene control in your movie, so here's the fla. All the code is explained. I haven't tested it much though, so if you encounter any problems, let me know

[attachment=2773:Movie_Control_2.fla]

BaconXBits

#7
Quote from: JoelasticotAs you guessed, the problem with the buttons not working was that the actions were "sent" to the nearest timeline, which is the timeline of the movie clip in which they are nested. To resolve this issue, we add the prefix "_root." to actions we want to be executed on the main timeline. However, this causes scene actions not to work because using _root. makes flash treat the timeline as a movie clip, and movie clips don't have scenes. I've created a simple function that will do the scene control in your movie, so here's the fla. All the code is explained. I haven't tested it much though, so if you encounter any problems, let me know

[attachment=2773:Movie_Control_2.fla]
Aha!  I understand now.  Thanks a ton for the help, I'll PM you or update this thread if I run into any issues.



Edit: Uh oh, some of the buttons aren't working as well as I would like them to!

Here's a diagnosis of what seems to be happening:
PREVIOUS SCENE: gotoandstop Preloader
PAUSE: Works perfectly!
PLAY: Works perfectly!
STOP: gotoandplay Menu
NEXT SCENE: gotoandstop Menu

Scene setup:
Preloader (1 frame)
Menu (will be animated and later halted with a stop(); )
Scene 1
Scene 2
Scene 3

This is kinda weird because the AS codes seem to be fine, but I wouldn't bet on it because I don't know what's with this "parameters" business.  Sorry to be such a novice at ActionScript!

Thor

Quote from: BaconXBits-How would I go about displaying the status of the subtitles (on/off) for a short time before fading?  This isn't necessary but it'd be nice to have.


I can think of 2 ways:

1. (actionscript heavy) Stick a dynamic text box somewhere on the screen and use a for loop to time out how long you want the text to be displayed (also using the tween class to adjust the alpha). This is probably the "proper" way to do this

2. Use a movie clip (with 2 stops) that's controlled by the subtitle button. It'll start off with a blank frame with a stop, and then have the text "subtitle on" for the next frame and have it fade off for X frames, where it will stop at a blank frame, where the process repeats with "subtitles off"

I say that the first way is the proper way because doing it the second way leaves room for the user to screw it up (if they're clicking the subtitle button repeatedly). I'll have to crack open some of my old files if you need help with the first method, but I should have the code to do it if you so decide to do it that way.

...actually there's a third way which may be easier to do than both of those. On the MC of the subtitle clip, attach a dyanamic text box about here (or anywhere)


The code for this one should be REALLY EASY too:

var toggleSubtitle:Boolean = false;
if(toggleSubtitle)
{
movieClip.textBox.text = "ON";
}
else {
movieClip.textBox.text = "OFF";
}


or something like that. It's been a while since I've coded anything

BaconXBits

#9
Quote from: Thor...actually there's a third way which may be easier to do than both of those. On the MC of the subtitle clip, attach a dyanamic text box about here (or anywhere)


The code for this one should be REALLY EASY too:

var toggleSubtitle:Boolean = false;
if(toggleSubtitle)
{
movieClip.textBox.text = "ON";
}
else {
movieClip.textBox.text = "OFF";
}


or something like that. It's been a while since I've coded anything
Bah, I can't get it to work properly, I tried putting that code on all of the movie clips in my button, to no avail.  Is there some prerequisite thing I have to do (like giving it an instance or something)?

And reposting my current problem in case anyone misses it:
What seems to be happening (tested in every scene):
PREVIOUS SCENE: gotoandstop Preloader
PAUSE: Works perfectly!
PLAY: Works perfectly!
STOP: Works perfectly!
NEXT SCENE: gotoandstop Menu

Scene setup:
Preloader (1 frame)
Menu (animated and later halted with a stop(); )
Scene 1
Scene 2
Scene 3

This is kinda weird because the AS codes seem to be fine, but I wouldn't bet on it because I don't know what's with this "parameters" business.  Sorry to be such a novice at ActionScript!

f0d

not to contradict joelasticot because he knows a great deal more code than i do

but i think you're making this much MUCH more complicated then it needs to be

first off... DONT USE SCENES. i dont care how helpful they are for you, just dont use them if you can, they fuck with actionscript big time. i cant think of a time when you'll ever really need to use them. from my experience theyre always more hassle than theyre worth.

try this: have your entire flash on the main timeline and simply have the next scene / previous scene button just gotoandplay whatever frame the scene starts on. if that doesnt work then youve got a real problem, not just a gay flaw in the way flash was built
I have more of a life writing this review at 1145 pm than you guys do making these movies. . .

f0d

... or is there a reason you want it in scenes
I have more of a life writing this review at 1145 pm than you guys do making these movies. . .

psi43

Quote from: BaconXBitsWhat seems to be happening (tested in every scene):
PREVIOUS SCENE: gotoandstop Preloader
PAUSE: Works perfectly!
PLAY: Works perfectly!
STOP: Works perfectly!
NEXT SCENE: gotoandstop Menu

Oh I think I know what your problem is. If you have like 450 frames in scene one, the first frame of scene 2 will be the 451st frame. After some scenes it's really hard to track. There is a script that, while you watch the movie, gives you the frame number as an output, I don't know how the script went tho, joelasticot does.

so when you click next scene it should be gotoandplay frame 451 and if you click play previous scene it should be gotoandplay frame 3 (assuming you have 1 frame for the preloader and 1 for the movie menu or something). That way you'd have to put different codes on your in-movie menu in each scene though.

Thor

#13
Quote from: BaconXBitsThis is kinda weird because the AS codes seem to be fine, but I wouldn't bet on it because I don't know what's with this "parameters" business.  Sorry to be such a novice at ActionScript!

It's not problem; the only reason why I know anything (which is close to none) is because I took an actionscripting class with some hardcore programmers and I guess I'm good at sponging up information that floats around me.

The code I posted assumes you put everything on the main timeline and NOT on buttons. This is the way you should be coding things ideally because:

1) Code is easier to find
2) Code is easier to change
3) You don't lose code having to hunt through MCs and buttons
4) If you're working on a team, THEY don't have to go hunt through MCs to find a line of code you did

It's a bit unnatural at first, but you get used to it after a while.

I'll try to throw together a .fla to show you how I'd do it, but I'm sure there's other ways that are less code heavy


[edit] heh. Looks like I created an infinite loop with the way I'm coding it. I'll get back to you on this.[/edit]

f0d

Quote from: psi43Oh I think I know what your problem is. If you have like 450 frames in scene one, the first frame of scene 2 will be the 451st frame. After some scenes it's really hard to track. There is a script that, while you watch the movie, gives you the frame number as an output, I don't know how the script went tho, joelasticot does.

so when you click next scene it should be gotoandplay frame 451 and if you click play previous scene it should be gotoandplay frame 3 (assuming you have 1 frame for the preloader and 1 for the movie menu or something). That way you'd have to put different codes on your in-movie menu in each scene though.
in other words

dont use scenes
I have more of a life writing this review at 1145 pm than you guys do making these movies. . .

psi43

if you have a bad computer scenes are important. If you animate everything in 1 scene it starts lagging like shit.

I always animate in scenes and I've never had a problem with them.

RobHalford

Well you can do that or make a new swf for each and just load it in via code.

QuoteBut nevvgrounds is totally different from 4chan. We are a different set of people.
Quote<+ukinojoe> kirbopher is a pile of jackets
<+ukinojoe> if you remove them all
<+ukinojoe> all thats left is a dead rat

Thor

Holy cow I'm rusty at programming. Sorry this took so long

https://udrive.oit.umass.edu/jgchan/baconsubs.swf
https://udrive.oit.umass.edu/jgchan/baconsubs.fla


I mixed up a = and == in there and couldn't figure out for the longest time why my boolean wasn't getting switched

BaconXBits

So, am I correct to assume that with the way I'm doing things, making functioning scene control buttons would be near-impossible?  Being the picky/stubborn fuck I am, I'd rather just dump those two buttons, and/or do simpler ones in the upper right corner or something.

Thor

#19
It shouldn't be hard at all.

button.onRelease = function()
{
nextScene();
}

and the command for the other one should be prevScene();

again, give the buttons the proper instance names and paths and it should work perfectly

[edit] also I only have flash 8 so  I  can't open any of the other .flas in here (i.e. I can't see what code you're using)[/edit]