简体   繁体   中英

AS3: Issue with movieclip within a button

I've been reading that you're not able to have a movieclip nested within a button, but I have this working on a button with a pulsing effect.

The issue I'm having is that it's not working on another button I created. I just wanted to create a blinking effect, but it's not reading it.

I've seen tutorials on how to make a movieclip into a button, but it's not working.

Any help would be appreciated.

Thanks!

You know what's funny is this exact same thing happened to me. I created a button with a movie clip and it worked fine once, then next time I tried to do it I couldn't get it to work. I think as a general rule of thumb, you shouldn't expect to nest movieclips within buttons. I can't remember what I did the first time, but I think it had to do with extending the movie clip class instead of extending simple button.

The problem of course is if you create a symbol of type button, it won't let you extend movie clip. Anyways, there is something that can easily solve your problem though.

What I do now is whatever movie clip you want, create it separately, use code to position it right on top of the button, then apply the following code.

mouseEnabled = false;
yourMovieclip.mouseEnabled = false;
yourMovieclip.mouseChildren = false;

That way your button will work fine (ie, your movieclip won't block your button's mouse detection). Hope that helps!

Why not just create a MovieClip and give it some event listeners for roll over and roll out that tell it to animate to a certain point on its timeline? You don't need to use the button symbol for buttons. I can't even think of the last time I did.

The SimpleButton type can get finicky. SimpleButtons are very very simple and not as complex as a MovieClip, and when you nest the MC into a Button, results are not always as expected and seemingly random. It'd be much less of a pain to create a MovieClip and give it event listeners on the first frame, for example:

stop();
this.addEventListener(MouseEvent.ROLL_OVER, hoverState);
this.addEventListener(MouseEvent.ROLL_OUT, normalState);

function hoverState(event:MouseEvent):void
{
   gotoAndStop(2);
}
function normalState(event:MouseEvent):void
{
   gotoAndStop(1);
}

Then just have whatever MovieClips you want on frames 1 and 2 to be your normal and hover states, respectively. This way, you just have MovieClips nested in MovieClips instead of nested in SimpleButtons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM