Problem: target path to movie clip element of a button

I’m trying to figure out how to use AS to access frames of a movie clip within a button symbol (using Flash MX 2004), and I seem to be stuck. I drafted a small test version of the FLA I’m working on, and it is attached to this message.

Specifically, my intention is to have a two-state button that goes into “selected mode” after the first mouse click, and then goes back to normal after a 2nd click. I can already handle the functional aspect of this using a global boolean like the one in the attached file. The problem is that I want to represent the current status of the button with a visual change; in the attached example FLA, the intention was to change the color of the text label on this button from grey to red when the button is in its “selected” state.

In this forum I found a similar question where someone had provided a “menu.fla” that had a row of buttons that acted more or less like a radio set, which is somewhat similar to my need. I’ve been trying to use the same sort of method, having converted the “up” state of the button text into a movie clip symbol with two frames (one for each state), and then trying to use AS to do a “gotoAndStop()” on the desired frame of the up label animation. The problem is that I cannot figure out how to actually make this work … no matter what sort of path I try to use to get to the movie clip animation within the button, I cannot seem to set the text animation to jump to the “selected” frame (2).

I think my problem is that I’ve been unable to glean any understanding from the Flash MX docs about the differences between an object name and a symbol name and an identifier and an instance name and a blah blah blah, or about which of them (if any) actually is an ID that can be accessed via ActionScript. Also, MX 2004 seems to provide almost no compile-time error checking on the validity of a target path either, so I’ve been reduced to just throwing every combination at it that I can think of. None have worked, so I’m at a loss.

If anyone can explain to me why the attached FLA doesn’t cause the text to stay red after a mouse click, no matter which of the commented out lines I try, it would undoubtedly be a big help to me.

(Please note that the button in this FLA uses a basic flashing animation for mouseovers … it was just something quick to implement to emulate the mouseover animation in my full file, so please don’t be distracted by it. Also note that I haven’t tried to implement any code to return the button to a non-selected status yet. One thing at a time.)

RESOLVED: It was apparently the nesting of a movieclip inside of a button that prevented the original target path from working (and one of the tutorials at this website seems to support that). Once I knew what the proper path syntax was and didn’t have to worry about that part anymore, eventually the rest fell into place pretty easily once I started using a movieclip for the button rather than an actual button.

I checked your file, and you made an error in your “mark text movieclip”:
the second frame doesnt have a stop(); actionscript, thus even if you DID provide the right targetting, the text would be red only during ONE frame. Yeah, we all do some stupid on-word mistakes sometimes too :stuck_out_tongue:

Also, the correct targetting syntax would be:

Simple! Root contains whatever movieclip. You gave that movieclip in the root an INSTANCE NAME of mark_btn. It’s the instance name (mark_btn)you have to target, not the original movieclip library name (marklock_btn). Same with the upinst_mc instance name you gave to your two-frame black text/red text movieclip.

I hope that helped!

(edited to add additional test results at end)

First off. thank you for your response, and for taking the time to look over my file!

Actually, I don’t think that’s right (how impertinent of me!). The only time the 2nd frame gets reached at all is when it is called by a gotoAndStop(), which stops the timeline right on that frame, so adding an actual stop() on that frame would be redundant. And the one and only reason I feel confident enough to say this is because the menu.fla file I downloaded from this forum (which was given as an example of how to do similar things) had it precisely the same way … and I had to look at it for a minute or so before I figured out why they had omitted the stop() statements on the additional frames. :slight_smile:

Also, the correct targetting syntax would be:

Simple! Root contains whatever movieclip. You gave that movieclip in the root an INSTANCE NAME of mark_btn. It’s the instance name (mark_btn)you have to target, not the original movieclip library name (marklock_btn). Same with the upinst_mc instance name you gave to your two-frame black text/red text movieclip.
It sounds right, but it didn’t seem to work … the text always stays dark grey no matter how many times I click on it (except when the mouseover animation is occurring, of course). I tried it both with and without the extra stop() statement you talked about in your first paragraph. Did making this change on your machine allow it to work? (By the way, the exact targeting syntax you listed was one of the ones I had already tried, failed with and commented out in the original file, unless I’m missing some subtle difference between the two.)

I read something in one of the ActionScript tutorials that suggested that one can’t nest a movieclip within a button and access it from AS … that one can only nest a movieclip only within another movieclip rather than any other type of symbol (if one wants to get at it via AS). Might this have something to do with the problem?

EDIT: okay, I just tried creating a movie clip nested within another movie clip, instead of within a button. And it does appear that this change allows me to use AS to change the frame of the innermost movie clip in exactly the way you suggest (using instance names). Furthermore, I was pleasantly surprised to see that onPress and onRelease events are still available for the outer movie clip (I’d have guessed they were only for buttons). However, unless I’m mistaken, this would require me to manually recreate my mouseover animation effects using event handlers like OnRollOver() and OnRollOut(), would it not? Is this the way serious Flash/AS developers usually create more complex buttons, or is there a better way?

You are missing some subtle difference between the two.
And yes, this is the way to create better buttons. For example, on which seamlessly fades out then fades in (i.e. transparency) when onMouseOver. So instead of static frames, AS-movieclip-buttons allow you to make more clever stuff.

Once you get used to it, it’s actually better to code your buttons (unless they REALLY ARE simple things like static frames). Coding buttons also allows you to change the text on buttons, so you could for example create one button template with a blank textfield and then generate the buttons (i.e. attachMovieClip) and assign those generated buttons some text.

Good luck :smiley: