AS3 Putting Buttons Inside Movie Clip

I am practicing AS3 (after years of AS2) and am having trouble having a button inside a movie clip talk to another movie clip on the main timeline. Here is the code:
OneButton.addEventListener(MouseEvent.CLICK, OneButtonClicked);
function OneButtonClicked(event:MouseEvent):void
MovieTarget.gotoAndStop(1);
MovieDescription.gotoAndStop("One");
TwoButton.addEventListener(MouseEvent.CLICK, TwoButtonClicked);
function TwoButtonClicked(event:MouseEvent):void
MovieTarget.gotoAndStop(2);
MovieDescription.gotoAndStop("Two");
The code above works, but if I put OneButton and TwoButton inside a movie clip, I know longer can target MovieTarget and MovieDescription. The reason I want to put OneButton and TwoButton inside it's own MC is so I can dim each button after it is clicked by toggling the playhead inside that MC. Help? Thanks!

Start over from the begining
press  f8 and chose movieClip then draw your untoggled button call the movie button then create another movie and create your toggled button or greyed out button and call it greyedButton.  Go to main stage add 2 button instances and 2 greyedButton instances( just drag from library).  you have 4 instances on stage.  give call instance names and place one them on top of each other so u can only see 2 buttons on stage.  put the greyed button under the button.
now with action script
button1.addEventListener(MouseEvent.CLICK, OneButtonClicked);
function OneButtonClicked(event:MouseEvent):void
MovieTarget.gotoAndStop(1);
MovieDescription.gotoAndStop("One");
button1.visible = false; //  here the greyed button will show
button2.addEventListener(MouseEvent.CLICK, TwoButtonClicked);
function TwoButtonClicked(event:MouseEvent):void
MovieTarget.gotoAndStop(2);
MovieDescription.gotoAndStop("Two");
button1.visible = true; // here button1 will go back to its orignal state
button2.visible = false // here the greyed button will show

Similar Messages

  • How to add button inside move clip and call it from main timeline?

    Hi,
    On the main timeline I  have a movie clip called clock_mc and playBtn
    playBtn is  placed in the center of clock_mc
    When you press playBtn clock_mc starts playing
    playBtn.addEventListener(MouseEvent.CLICK, playClock);
    function playClock(event:MouseEvent):void
        if (event.target == playBtn)
            clock_mc.play();
            playBtn.visible = false;
            trace ("play button was clicked");
    This is working fine for me.
    But I want to add replayBtn to the last frame of clock_mc and set up the function on main Timeline.
    Another words when the clock_mc rich last frame you see replayBtn.
    code example:
    replayBtn.addEventListener(MouseEvent.CLICK, playClock);
        if (event.target == replayBtn)
            clock_mc.play();
            replayBtn.visible = false;
            trace ("replay button was clicked");
    I've tryed to placed the replayBtn on the stage on the main timeline and I've set it up to replayBtn.visible = false;
    And then I add replayBtn.visible = true; to last AS frame of clock_mc but it wont work
    Even when I put the button physically to the last frame of clock_mc it will not work either.
    Please help

    I've solved the problem:-)
    I've set replayBtn.visible = false; on first frame of clock_mc
    and  replayBtn.visible = true; at the last frame
    and than as you sugested I'v add:
    clock_mc.replayBtn.addEventListener(MouseEvent.CLICK, replayClock);
    function replayClock(event:MouseEvent):void
            clock_mc.play();
            trace ("replay button was clicked");
    I couldn't see replayBtn at the firs stage because I have clockTween assosiated with clock:
    clockTween = new Tween(clock_mc, "x", Regular.easeOut, -469,438, .5, true);
    and I had replyBtn in the wrong place so when clock_mc was coming up on the stage replayBtn was on the left side of the stage :/
    Now I have to solve only one thing.
    Maybe you would have any suggestions please.
    I've set up stop(); in a first frame of clock_mc
    that when you see clock_mc sliding in it has to wait for playBtn to be clicked
    because I have two tween:
            clockTween = new Tween(clock_mc, "x", Regular.easeOut, -469,438, .5, true);
            playTween = new Tween(playBtn, "x", Regular.easeOut, -720,514, .5, true);
            playBtn.visible = true;
    so when you click on playBtn:
    function playClock(event:MouseEvent):void
        if (event.target == playBtn)
            clock_mc.play();
            playBtn.visible = false;
            trace ("play button was clicked");
    everythink is working fine except when I clik on replayBtn it play for I sec because there is stop(); on the first frame of clock_mc

  • Buttons inside movie clip dont work

    I have a simple HTML website with 5 buttons one of which, a movie clip, drops down 3 more buttons but the buttons dont always work. I get wierd issues for instance: whether I'm on the mcs page or another page completly the drop down buttons only work when Im on the parent movie clips page. When the buttons do work and you click on the button of the page your on  they only work once then the whole issue repeats itself. Hopefully to clarify here is the code inside of the movie clip that directs the drop down buttons.
    stop();
    var cdButton:URLRequest= new URLRequest("character desin.html");
    cd_btn.addEventListener(MouseEvent.CLICK, cd);
    function cd(event:MouseEvent):void
            navigateToURL(cdButton,"_self");
    var caButton:URLRequest= new URLRequest("concept art.html");
    ca_btn.addEventListener(MouseEvent.CLICK, ca);
    function ca(event:MouseEvent):void
            trace("ca_btn");
            navigateToURL(caButton,"_self");
    var dsButton:URLRequest= new URLRequest("draw sketch.html");
    ds_btn.addEventListener(MouseEvent.CLICK, ds);
    function ds(event:MouseEvent):void
            trace("ds_btn");
            navigateToURL(dsButton,"_self");

    From what I see you are trying to somehow program a Actionscript only iframe navigation. That will never work without an external Interface call to the Browsers Javascript. This is complicated stuff and surely not what you have in mind. If concept art, draw sketch etc. are all separate swf files, you should load them (instead of the html you embedded them in)

  • Buttons in Movie Clips, Movie Clips in Movie Clips

    Here goes. I have a scene with a button in the timeline, that
    targets a frame in a movie clip, which is essentially the content
    area of the layout. this is the code used:
    on (release) {
    textmov.gotoAndPlay ("challenge");
    This works fine and dandy. Now the problem. Within this
    "Content" movie clip, i have another movie clip with a button in
    it. This clip is designed to tween in then upon clicking a close
    button tween out. When I test it the button doesn't have rollovers
    like and I can't get it to talk to the clip above it to play the
    close tween.

    > I am still struggling with the fact, that upon testing,
    buttons in movie clips
    > do not exhibit their various states. Up, Over etc. I'm
    relatively sure that you
    > can have buttons in Movie Clips. I've also noticed that
    any graphic symbols
    > within a Movie Clip produce the hand, when the mouse
    cursor is Over them, just
    > like a button would. All of this happens, when testing
    in the FlashPlayer.
    is there any place you could kindly upload the source file
    for me to check ?
    > Do buttons operate independently of the Movie Clip
    timeline they are placed in?
    that is correct, button should work independently to movie
    clip.
    it only react to mouse upon entering the HIT state (which is
    invisible to user)
    and stops reacting once the mouse is off that state.
    > I have one Movie Clip with a one frame time line, should
    a Button symbol work
    > it it?
    of course it should work...
    Try to upload the source, let us check it out for you, spare
    you time on guessing :)
    Best Regards
    Urami
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • Buttons in movie clip won't bring up scenes

    I've created a movie clip within my main scene.
    I have 6 buttons in that clip. I would like these buttons to
    call up the appropriate scenes but it isn't. I don't know whether I
    cannot have buttons in movie clips call up new scenes or if my
    actions script is simply wrong.
    Here are some of the actions I've tried to upload the scene
    or swf files:
    thanks.
    on (release) {
    _root.gotoAndPlay("instance name");
    ----Also, named 1st frame of scenes with matching instance.
    on (release) {
    _root.gotoAndPlay("scene name");
    on (release) {
    gotoAndPlay("scenename",1);
    on (release){
    uploadMovie ("name.swf",1);
    }

    use frame labels only and use the goto methods (like your
    first 2 goto statements) and not the goto functions (like your last
    2 goto statements).
    also, there is no uploadMovie() method in actionscript. use
    loadMovieNum() if you want to load name.swf into _level1.

  • How do I create a play button for movie clip using AS3

    Hello.
    Bit new to this and have been searching the adobe forums and google. I am trying to create a button that will play an imported MovieClip.
    I have a movie clip that I've imported into it's own layer (Layer1) Frame 1.  I've given the MovieClip an instance name of foundationMovie.
    I've created a button and have that on its own layer(Layer2) above layer1, it is also in Frame 1.
    I've added a
    stop (); action to layer2
    The video is not set to autoplay.
    I want the video to start playing when the viewer clicks the button.  I know I've got to put some kind of event listener using AS3 in my timeline somewhere.
    I've found some code and I've been trying to work with it.  I'm sure I've mutilated it beyond usability but this is what I've got.
    stop ();
    player.addEventListener(MouseEvent.CLICK,play);
    function play(event:MouseEvent)
    gotoAndPlay("foundationMovie");
    If someone could point me the right direction or help me with my code I would really appreciate it.  Thanks.

    First, you need to clear up what you are working with... a movieclip and a video are usually entirely different things.
    Next, your code may get you started on your way with some changes.   You shouldn't use "play" as a function name due to there already being a play() method/function in Flash.
    If the movieclip is a movieclip and has an instance name of "foundationMovie", and your button has an instance name of "player" then the following adjusted code would normally work...
    stop ();
    player.addEventListener(MouseEvent.CLICK,playMovie);
    function playMovie(event:MouseEvent)
         foundationMovie.play();

  • How to _root in as3 (buttons in movie clip referencing to main timeline)

    Hi, I created buttons within a movie clip that i placed in the main timeline.I am  a novice to as3. I just wanted the button to go to the frame label of the main timeline. i used to do this with _root in the old flash. how do i do this?
    thumb02_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
    function buttonClicked(event:MouseEvent):void
        gotoAndPlay("slide2");

    Thanks for the quick reply!
    somehow i must be doing something wrong though. It's not working...
    I added a stop to the "slide02" labeled section of the main timeline.
    and I also added a stop to the beginning and end of the movieclip. Am I doing something wrong? attached is my file....thanks!!
    stop();
    thumb02_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
    function buttonClicked(event:MouseEvent):void
        MovieClip(this.root).gotoAndPlay("slide2");
    stop();

  • Variables inside movie clips?? in Flash CS4 (AS3)

    Hi everyone,
    I was wondering if it is possible to have variables such as Int 's stored inside or together with a movie clip??
    Thank you!

    Yes, you can store them inside manually when you create the movieclip or you can assign a variable to a movieclip during run time without having created the variable previously.
    myMovieclip.newVariable = some value;

  • Button in movie clip linking to next frame

    I've included a button in a movie clip on frame 1 of the main
    timeline. The button has a motion tween that ends on frame 76 of
    the movie clip. I want the button to link to frame 2 on the main
    timeline. However, when I test the movie, it cycles endlessly
    without stopping at the end of the movie clip to allow the user to
    click on the button.
    Here's the AS3 code I put on the Actions layer on Frame 76 of
    the movie clip:
    stop();
    link_btn.addEventListener(MouseEvent.CLICK,link_btnClick);
    function link_btn(event:MouseEvent):void {
    gotoAndStop(2);
    Any ideas? It's for school and I need it done tonight or
    tomorrow morning by 8 a.m. Central. Yikes.

    I'm getting compiler errors S1061 and S1120 attached to code:
    link_btn.addEventListener(MouseEvent.CLICK,link_btnClick);
    S1061:
    Call to a possibly undefined method addEventListener through
    a reference with static type Function.
    S1120:
    Access of undefined property link_btnClick.
    I don't know what the errors mean. Anybody?

  • Remove Child and Event.SOUND_COMPLETE not working inside movie clip. What's the problem?

    I have a movie clip that is called to the stage. The user then clicks a button and music plays. As the music starts, another movie clip is called, a simulation of  an equilizer. There are several things that should happen:
    1) When the user closes the movie clip the music is supposed to stop playing and the equilizer movie clip is removed. What actually happens is the music stops playing but  the equilzer movie clip is not removed.
    2) When the music is finished playing the equilzer is supposed to be removed from the stage and the play button is reactivated. But none of that happens. When I click on the movie clip a second time equilizer is still there and the play button is not reactivated.
    Here's the code that calls the movie clip to the stage.
    stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtons);
    function goButtons(event:MouseEvent):void
        if (event.target == Song_bnt)
            SoundMixer.stopAll();
            addChild(myPlaySong);
            myPlaySong.x = 304;
            myPlaySong.y = 105;
            //event.stopImmediatePropagation();
    Here's the code in the movie clip:
    import flash.media.Sound;
    import flash.events.Event;
    stop();
    var playRayJaySong:RJSong;
    var playRayJaySongChannel:SoundChannel;
    var equilizer:Equilizer;
    equilizer = new Equilizer();
    playRayJaySong = new RJSong();
    //Plays music, inactivates buttons, and adds the equilizer to the stage.
    PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
    function songPageButton(event:Event):void
        playRayJaySongChannel = playRayJaySong.play();
        PlaySongRJClip.visible = false;
        ClicktoPlaySong.visible = false;
        addChild(equilizer);
        equilizer.x = 269;
        equilizer.y = 246;
    //Removes the equilizer from the stage when the music is complete.
    PlaySongRJClip.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
        function rjSoundComplete(e:Event):void
        PlaySongRJClip.visible = true;
        ClicktoPlaySong.visible = true;
        removeChild(equilizer);
    //Removes the equilizer and event listeners from stage and calls dispatch event to close the movie clip.
    closeSong_bnt.addEventListener(MouseEvent.MOUSE_DOWN, CloseSong);
    function CloseSong(event:MouseEvent):void
        removeChild(equilizer);
        dispatchEvent(new Event("RemoveMSong"));
        PlaySongRJClip.removeEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
        PlaySongRJClip.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
    //Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
    myPlaySong.addEventListener("RemoveMSong", RemoveSongClip);
    function RemoveSongClip(e:Event):void
        SoundMixer.stopAll();
        removeChild(myPlaySong);
    Any thoughts?

    I figured out the problem. Here's how I reorganized the code (all in one frame).
    //Code for Ray Jay song.
    var playRayJaySong:RJSong;
    var playRayJaySongChannel:SoundChannel;
    playRayJaySong = new RJSong();
    myPlaySong.equilizer_inst.visible = false;
    //Plays the song.
    myPlaySong.PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
    function songPageButton(event:Event):void
        playRayJaySongChannel = playRayJaySong.play();
        playRayJaySongChannel.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
        myPlaySong.equilizer_inst.visible = true;
        myPlaySong.PlaySongRJClip.visible = false;
        myPlaySong.ClicktoPlaySong.visible = false;
    //Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
    myPlaySong.closeSong_bnt.addEventListener(MouseEvent.CLICK,RemoveSongClip);
    function RemoveSongClip(e:Event):void
        SoundMixer.stopAll();
        removeChild(myPlaySong);
        myPlaySong.equilizer_inst.visible = false;
        myPlaySong.PlaySongRJClip.visible = true;
        myPlaySong.ClicktoPlaySong.visible = true;
        playRayJaySongChannel.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
    //Resets all of the movieclips to their orginal state.
    function rjSoundComplete(e:Event):void
        myPlaySong.equilizer_inst.visible = false;
        myPlaySong.PlaySongRJClip.visible = true;
        myPlaySong.ClicktoPlaySong.visible = true;
    Thanks all for your suggests and input.

  • Advanced Button with Movie Clip and Fading

    Problem: I'm trying to create a bottun that when you roll
    over it it plays a movie clip and also fades in and out on roll
    out. It is similiar to the three main navigating buttons on the
    following site.
    http://www.fjcruiser.ca/
    the buttons with the compasses that appear are the ones I am
    talking about.
    I already know how to make buttons, I just can't figure out
    the actionscripting to load the movie and also fade in and fade out
    according to roll over and roll out.
    Please help. Thank everyone.

    Amazingly, I actually know exactly how to do this. And it
    only requires about 4 lines of code in the _root layer and on the
    button.
    Instead of having the rollover load an external movie, you
    want the have the rollover execute an on(enterFrame) function that
    tells each newly entered frame of your movie to check to make sure
    the mouse is still on the button, and if not, send the movie
    playhead backwards.
    So, put that sampleMovie right on the stage with the button.
    Then write the code in the _root so that says: as long as the mouse
    is over the button, the movie will advance to nextFrame(). When it
    gets to the next frame, again the code checks to see if the mouse
    is on the button, if so, the movie is instruct to go one more next
    frame (which is tweening the fade, right?) again, over and over
    until the stop() at the last frame. But, if while while entering a
    frame, the code finds that the mouse is no longer over the button,
    it does the same thing but this time instructs prevFrame(), and so
    on, going prevFrame (backwards, in other words) as long as the
    mouse is not on the button.
    The result of the above is a gradual fade in and out,
    depending on whether the mouse is hovering. This, as opposed to an
    abrupt disappearing graphic on(rollOut).
    Click the below link for the .fla that demonstrates this
    technique (which, by the way, I learned from Joshua Davis'
    excellent book, "flash to the core". Check it out at Amazon, or
    wherever. Lots of cool tricks).
    click here for
    fade_Movie example

  • Multiple click points for one button and movie clip

    I am trying to make a single button into a multiple click
    point. I have a movie clip on the stage and I have an invisible
    button over it. The movie clip consists of a single timeline that
    has an ambient animation running and looping intially. I have three
    more labeled sections of that timeline that each contain a
    different animated sequence as click point animations for that
    movie clip. I want the user to click on the button on the stage and
    the first labeled click point animation of that movie clip will
    play. I want that action to be stored so that when the user clicks
    again then the second labeled click point animation will play then
    they will click for the third in the same way. In between user
    clicks I want the ambient animation loop in the beginning of that
    movie clip timeline to play. When the user has clicked the 3rd and
    last animated sequence then the whole thing will reset and be
    available again. Can anyone let me know how that can be
    accomplished. I originally scripted it through tell target to play
    the first but I don't know how to move forward. Thanks!

    What version of Flash are you using? Telltarget is very
    old... try something like this:
    // array of the animations
    myAnims = ['firstAnim','secondAnim','thirdAnim']; // these
    are also frame labels
    // your current animation index in the array, arrays start at
    0,
    // so we start at -1 which is like before anything
    currAnim = -1;
    // function to play the next animation
    function nextAnim(){
    // add one to the current animation index
    currAnim++;
    // if you've reached the end of the array, start back at 0
    if(currAnim >= myAnims.length)currAnim = 0;
    // now tell the MovieClip to play based on the value of the
    current array index
    myMovieClip.gotoAndPlay(myAnims[currAnim]);
    Then on the button you just put:
    on(release){
    nextAnim();
    And at the end of each animation on the timeline, put:
    gotoAndPlay(1);
    And at the end of the ambient loop at the beginning I guess
    you have that, too, so it loops.
    Hope that helps

  • Successfully imported external swf, can not put it into movie clip

    Hello all,
    I have started learning AS3 and gradually getting used to, trying to put external swf into movie clip.
    Successfully imported target swf and put into stage, when I publish this I see target swf is playing.
    import flash.display.MovieClip;
    var BGLoader:Loader = new Loader();
    var BGurl:URLRequest = new URLRequest("HomeBG.swf");
    BGLoader.load(BGurl);
    BGLoader.y = 0;
    BGLoader.x = 0;
    addChild(BGLoader);
    As next step I want to put this swf into movie clip and get more control, but when I publish bellow only I see is empty background, without any errors.
    import flash.display.MovieClip;
    var BGLoader:Loader = new Loader();
    var BGurl:URLRequest = new URLRequest("HomeBG.swf");
    BGLoader.load(BGurl);
    BGLoader.y = 0;
    BGLoader.x = 0;
    //addChild(BGLoader);
    var animMC = MovieClip(BGLoader.content).getChildAt(0) as MovieClip;
    addChild(animMC);
    Is anything missing?
    Any help would be appreciated, thanks.

    You can only access Loader.content after Load completed successfully.
    Try this,
    import flash.events.Event;
    var BGLoader:Loader = new Loader();
    var BGurl:URLRequest = new URLRequest("HomeBG.swf");
    BGLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
    BGLoader.load(BGurl);
    BGLoader.y = 0;
    BGLoader.x = 0;
    //addChild(BGLoader);
    var animMC:MovieClip;
    function completeHandler(event:Event)
         animMC = event.currentTarget.content;
         addChild(animMC);

  • Deactivate a button until movie clip is complete

    I am creating several self study courses for my company's
    intranet. I added buttons for nextFrame and prevFrame to allow the
    user to navigate at their own pace. My problem is that a frame may
    include a movie clip that needs to play before the next button
    appears (or is activated).
    Thank you from an old dog trying to learn new tricks.

    Hello!
    Maby you could disable your button with this little script in
    the timeline:
    YourButton'sInstancename.enabled = false;
    That will disable your button.
    Enyways, if your problem is what I think it is.. you might
    reslove your problem by making the movieclip like this:
    Start by making a new movieclip. Name it as you would like
    it.
    In the first frame of your MC (movieclip) start making the
    animation with tween and whatever you want. When the animation is
    done, make a new layer INSIDE your MC and on the frame where your
    animation stops, drag in the button, or make something and convert
    it to a button. Make sure you have this script in the same frame as
    your button: stop() ; So, when the animation is finished, the MC
    stops at the button.
    After that, just type the script inside your button. Like
    ex.:
    on (release) {
    gotoAndStop("scene 1", 1);
    You have to change scene 1 to the name of your scene which
    you want to go to after clicking the button, and change 1 to the
    framenumber you want to go to.
    Hope this helps!
    Happy smile,
    SveinMikkel.com

  • Buttons and movie clips

    I'm sorry if this question has already been answered. I
    searched the archives and couldn't find what I was looking for.
    Basically what I want to do is use a button to play a movie when
    pressed. The problem is I can't figure out how to do it.
    1. I've created 3 buttoms and three movie clips.
    2. I created a layer for the background which has text on it
    that says "press to view".
    3. I created another layer for the buttons and one layer for
    the button text
    4. I created an actions layer and put a stop action in frame
    1
    5. I added another layer for the movie clips on frame 2
    (mailflow_mc), frame 3 (reject_mc), frame 4 (fullrate_mc) and
    labeled each frame accordingly.
    6. Add action script for each button:
    on (press) {
    gotoAndPlay("reject");
    When I play the movie the animations will not load and they
    flash fast. Any suggestions?
    Thanks,
    Mimi

    if you have a frame labelled reject you can use:

Maybe you are looking for

  • I got a iphone 4 , and it says its charging but it wont power on ? what do i do ?

    i got a iphone 4 , it says its charging but doesnt power on ? -_- what do i do?

  • IOS 7.0.4 battery issue on my 4s

    I normally don't post, I can't help but voice my frustration. My wife and I have the same type iphone, 4s I always update before she does. Recently updated my iphone 4s to iOS 7.0.4 around Nov. 22, Since my update I've had a problem getting through t

  • Caching of adhoc queries=filesystem sometimes at 100%

    WLS_PRODUCT_VERSION=10.3.6.0 OS: Red Hat Linux 5 DB: 11.2.0.2.0 OBIEE: 11.1.1.6.2 Hello. When someone runs a silly query via OBIEE we sometimes see .TMP files that have ranged in silly sizes (up to 25GB!) We have been caught by this as the growth is

  • GRC 10.1 custom security policy

    On GRC Java system, I am not able to create custom security policy under UME->Configuration->Security Policy. I am able to create on all other systems except GRC and NWDI system   I it related to support pack level or facility is not available on the

  • Import csv files into Ical

    Is there a way to import csv into Ical? I need the "importing csv into Ical" for dummies version. Thanks.