AddListener for a button inside a movieclip in the library?

Could someone point me in the right direction on how to add a listener for a button inside a movieclip in the library?

Example:
Root-> work_mc-> workss_mc (added with Addchild) (timeline)

There are workss_mc in the library which is charged when someone clicks on a button inside work_mc. This is achieved with addChild. In workss_mc there is a close button to close it. I encountered problems with the work of navigation with this b/c I have to declare and create a single instance of workss_mc within a scope where it is visible to both managers of click, this will place the two managers in one place. So to do this I would need them all be designating the code of navigation, the root.

So, how can I access the root workss_mc?

It is good news.

Now, what happens if you just after on the main timeline - none other than the trace:

function clickHandler(event:MouseEvent) {}

workss_mc = new mc_workss();

workss_mc.addEventListener ("closeButtonClick", onCloseClick);

workss_mc.x = 225;

workss_mc.y = 200;

addChild (workss_mc);

removeChild (work_mc);

}

function onCloseClick(e:Event):void {}

trace ("clicked")

}

Tags: Adobe Animate

Similar Questions

  • AS3 button inside a movieclip

    I only started to learn AS3, I have a very simple question, but I can't understand it.

    I have a movieclip with instance name mcChange, and it has a button inside btnBack. When the button is clicked, I want to debut at the first image on the main stage.

    I would appreciate if you could help me with this one.

    where is the code?

    Chronology of mcChange when the button exists in case:

    btnBack.addEventList...

    If during the kinship of mcChange chronology after mcChange and btnBack exist:

    mcChange.btnBack.addEventList...

    the code that must be in the listener function depends on where the code is located and where the main stage is relative to the location of the code, if someone is bound to suggest any MovieClip (root) to the main timeline, which is always bad coding but will often work of reference.

  • Load a movieClip in the library, then changing the text inside

    I have a movieClip in the library with the name of binding as "LinkClass" class  I can do appear on the scene, but there is an area of dynamic text inside called "linkText" that I can't seem to make it work.  Ideas?  Here is the code:

    myLink = new LinkClass();

    myLink.name = "linkButton";

    box.boxMC.linksMC.addChild (myLink);

    myLink.linkText.htmlText = 'hi. '

    so, you don't have a child object named linkText in your object with the LinkClass class.

    If you think that you do not have such an object, make sure that it is not part of a timeline Tween and there on frame 1 of your LinkClass object.   If linkText is created on the stage with the tool text, click it to select it in the properties panel, paste linkText.  If you think you've done everything right, paste a screenshot here that shows your textfield on selected scene, the calendar, and the properties panel.

  • Load the object MovieClip in the library in the container

    Hello

    I have a MovieClip in the library with the CloseButtonbinding name. Now, I want to load this MovieClip in a createjs container object:

    var popupObj = new createjs. Container();

    var closeBtn is new lib. CloseButton();

    closeBtn.x = 20;

    closeBtn.y = 20;

    popupObj.addChild (closeBtn);

    It does not work. When I add it to the stage instead, it works fine:

    var that = this;

    var closeBtn is new lib. CloseButton();

    closeBtn.x = 20;

    closeBtn.y = 20;

    that.addChild (closeBtn);

    Any ideas?

    It was only a snippet, I add the container to the scene. I use a container, because it has more elements such as shapes and text in:

    var that = this;

    that.createPopup = function() {}

    var popupObj = new createjs. Container();

    popupObj.name = "popup".

    var popupWidth = 260;

    var popupHeight = 140;

    var popupMargin = 14;

    var popupShape = new createjs. Form (new createjs. Graphics ().beginFill("#FFFFFF").drawRoundRect (0,0, popupWidth, popupHeight, 8) .endF ill());

    popupShape.alpha =. 96;

    {popupShape.on ("click", function ()}

    Do nothing, to prevent clicking on parent elements

    });

    var pt1 is new createjs. Text ("Title", "16px Arial", "#333333");

    Pt1.name = "pt1";

    Pt1.x = popupMargin;

    Pt1.y = popupMargin;

    var Pt2 is new createjs. Text ('Content', "" BOLD "14px Arial", "#333333");

    Pt2. Name = "pt2"

    Pt2.x = popupMargin;

    Pt2.y = Math.floor (popupMargin + 30);

    var closeBtn is new lib. CloseButton();

    closeBtn.x = 20;

    closeBtn.y = 20;

    popupObj.addChild (popupShape);

    popupObj.addChild (pt1);

    popupObj.addChild (pt2);

    popupObj.addChild (popupButton);

    popupObj.addChild (closeBtn);

    popupObj.x = 40;

    popupObj.y = 20;

    that.addChild (popupObj);

    }

    But I found the error. I had to call the function addChild (closeBtn) after that I added the popupShape.

  • After you install the update for LR cc 2015/5 AffichageOptions in the library doesn´t Module shows any type of lens. What has gone wrong?

    After you install the update for LR cc 2015/5 AffichageOptions in the library doesn´t Module shows any type of lens. What has gone wrong?

    See this thread on the official Adobe feedback site: Lightroom CC 2015: objective metadata missing when importing field. Community customer Photoshop family

  • Problem using a button inside a movieclip and make change a button what it does based diffferent.

    First question is that I can't get any coding inside my movieclip to affect the main storyline.

    Go as simple as possible, I reduced to

    "

    parent.nextFrame ();

    "

    I thought less coding means less room for mistakes, but there is nothing at all.

    Next issue is my button ignore my IF statement.

    "

    If (this ._currentframe! = 4 | 10 | 16 | 22: 28: 34 | 40 | 46 | 52 | 58 | 64 | 70) {}

    prevFrame();

    } else {}

    gotoAndStop (3);

    }

    "

    This button makes prevFrame no matter what chassis it is on.

    I have read the tutorials and maintained using code people offered as solutions, but nothing did. Quick response appreciated, I have a deadline for this. Thank you

    You may NOT use any encoding in this movieclip as the goto, play() and stop().

    but, if you CAN use a coding in this movieclip to control the parent movieclip. for example,.

    _parent.nextFrame ();

    and that the code of the button must be:

    If (this ._currentframe! = 4 |) This ._currentframe! = 10 | This ._currentframe! = 16 | This ._currentframe! = 22 | This ._currentframe! = 28 | This ._currentframe! = 34 | This ._currentframe! = 40 | This ._currentframe! = 46 | This ._currentframe! = 52 | This ._currentframe! = 58 | This ._currentframe! = 64 | This ._currentframe! = 70) {}

    prevFrame();

    } else {}

    gotoAndStop (3);

    }

  • Cannot click on buttons inside draggable movieclip.

    I have a removable clip, mc_PI on the stage in which I have another movieclip, mc_PIcontainer in which I load an image.  Then, I place a few buttons, btn_Ant1, btn_Ant2, etc. inside mc_PI.

    mc_PI hangs out just fine within the limits that I said, but I can't click the buttons that are inside mc_PI.  I need the buttons inside the mc_PI, because I need them to drag as well as the image in mc_PI.mcPIcontainer.  My code is:

    ///////////////////
    Dragging.
    ///////////////////
    var container: MovieClip = mc_PI.mc_PIcontainer.createEmptyMovieClip ("container", 1);
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener (this);
    mcLoader.loadClip ("images/PI.jpg", mc_PI.mc_PIcontainer.container);

    function onLoadInit(mc:MovieClip)
    {
    mc.forceSmoothing = true;
    MC._quality = "BEST";
    }

    mc_PI.useHandCursor = false;
    mc_PI.onPress = function (): Void
    {
    startDrag (this, false,-910,-1769, 1, 36);
    }

    mc_PI.onRelease = mc_PI.onRollOut = function (): Void
    {
    stopDrag();
    }


    /////////////////////////
    Buttons.
    /////////////////////////
    mc_PI.btn_Ant1.useHandCursor = true;
    mc_PI.btn_Ant1.onRelease = function (): Void
    {
    trace ("clicked mc_Ant1");
    }

    to check click parent1 child1, use:

    {parent1.onRelease = Function ()}

    {if (parent1.child1.HitTest (_xmouse, _ymouse))}

    do everything.  the user has clicked Child1

    }

    }

  • access a button inside a movieclip

    Hey...

    IM pretty new to Flash, I have a problem that took hours, only not to get sorted, so I'll try my luck here...

    I basically made a substitution menu that is nested within a movieclip. the movieclip is placed on 1 st. on the main Timeline frame and I want the buttons inside the clip to the user of a different image on the main timeline, but no matter what I do, it's just does not...

    Here are some of it solutions I've tried to do:

    function work1(e:Event)

    {

    //MovieClip(parent.parent).gotoAndStop ("work1")

    //gotoAndStop ("work1")

    //this.gotoAndStop ("work1")

    //parent(gotoAndStop ("work1"))

    //MovieClip(this.parent).gotoAndStop ("work1")

    //MovieClip(parent.gotoAndStop ("work1"))

    //this(gotoAndStop ("work1"))

    //main.gotoAndStop ("work1")

    //root.gotoAndStop ("work1")

    //MovieClip(root).gotoAndPlay ("work1")

    //MovieClip(stage).gotoAndPlay ("work1")

    MovieClip (root.parent.parent) .gotoAndStop ("work1");

    }

    work1_btn.addEventListener (MouseEvent.CLICK, Group1);

    I hope someone can help...

    Of course, LOL and thanks, glad that I can help you.

    for future things, (which didn't need to wait for a rendering as this project), if you want to get specific with your listeners (instead of a listener to the stage), you can add the following:

    var buttons: Array = new Array (btn1_name, btn2_name, btn3_name);

    for each {(var btn in buttons)

    btn.addEventListener (MouseEvent.CLICK, clickHandler);

    }

    That will restrict the event to those buttons... but use your button names in the table of course.

  • Need help to connect the buttons inside a movieclip

    Hello

    I have five mcButtons inside a movieclip. I want to, so if the user clicks on the 1 mcButton it won't Stop on frame 2. I want then the other four mcButtons that were not clicked to stop on frame 2. Can't do the second part of this work. my code is below. Any help would be greatly appreciated.

    Thanks in advance

    prev08.Btn1.ID = 0;

    prev08.btn2.id = 1;

    prev08.btn3.id = 2;

    prev08.btn4.id = 3;

    prev08.btn5.id = 4;

    prev08.btn1.addEventListener (MouseEvent.CLICK, getXML08)

    prev08.btn2.addEventListener (MouseEvent.CLICK, getXML08)

    prev08.btn3.addEventListener (MouseEvent.CLICK, getXML08)

    prev08.btn4.addEventListener (MouseEvent.CLICK, getXML08)

    prev08.btn5.addEventListener (MouseEvent.CLICK, getXML08)

    function getXML08(event:MouseEvent):void

    {

    for (var i: int = 0; i < 18; i ++)

    {

    if(i == Event.Target.ID)

    {

    event.target.gotoAndStop (2)

    }

    on the other

    {

    prev08.getChildAt [i] .gotoAndStop (1)

    }

    }

    they all go to the same frame?  that makes no sense.

    If you want to run each in their own framework 1, except just clicked the button that should go to its Framework 2, direct all frame them 1 followed by the evt.currentTarget goes to frame 2:

    function getXML08(e:MouseEvent) {}

    for (var i: int = 1; i<>

    prev08 ["BNT" + i] .gotoAndStop (1);

    }

    MovieClip (e.currentTarget) .gotoAndStop (2);

    }

  • How to access a button inside a MovieClip that is the source of a scrollpane?

    Hello world

    I created a crollpane in my flash file and the source of the pane scrolling is a movieclip that contains a button.

    Now, I want to add a function to stop this button to link to an image in the main timeline.

    Could someone tell me what is the right as3 code to access this button?

    Thank you!

    To target the movieclip which is the source of the pane scrolling you can use:

    MovieClip (sp.content) / / where sp is the name of the instance of scrollpane

    So, to target the button with this movieclip...

    MovieClip (sp.content).btn.addEventListener (... etc.

  • Creating movieclips from the library "random" then move them.

    Hey everybody,

    I am currently working on a type of runner free 2D game for Android and iOS. What I'm trying to accomplish is spawning in some clips, which are sets of platforms formed how I'd like, when the game of previous platforms reaches a certain point on the left of the stage. I want the movieclip to come slightly to the right of the stage and move them to the left. This will keep spawning, randomly, one of the dozen sets platforms very much, making a runner for the infinite. The game I suppose that could be described as something like Jetpack Joyride, but platforms to add and subtract the jetpack. Anyone know it to spawn in movieclips and move them conditionally at best? Thank you in advance!

    -John

    To generate the library dynamically in aAS3 clips you must first assign a class name to each library.  Then add these class names in a table so that you can randomly select one of them.  To add them, you can use the name of the class as follows...

    var ClassRef: Class = Class (getDefinitionByName ("className"));

    var classInstance: * = new ClassRef();

    addChild (classInstance);

  • Randomly generate movieClips from the library onto the stage

    Hello

    I'm calling the objects from the library for a collection set.

    Major problems with how best to attribute the good and bad objects update later a score.

    Can anyone help me how can I first assign the clips in the library in an array of good and bad and then after randomally fill the stage with them.

    Concerning

    James

    see you never fake in your output panel, when using:

    public void placeWords() {}

    random location

    var x: Number = Math.floor (Math.random () * mapRect.width) + mapRect.x;

    var y: Number = Math.floor (Math.random () * mapRect.height) + mapRect.y;

    check all blocks to see if it's over everything

    var isOnBlock:Boolean = false;

    for (var j: int = 0; j

    If (blocks [j].hitTestPoint(x+gamesprite.x,y+gamesprite.y)) {}

    isOnBlock = true;

    break;

    }

    }

    not on everything, so use location

    trace (isOnBlock);

    If (! isOnBlock)

    {

    var goodObjects:Array = ["WordObject1"];

    var badObjects:Array = ["WordObject2"];

    If (Math.Random)<>

    {

    var r: int = Math.floor (Math.random () * goodObjects.length);

    var classRef: Class = getDefinitionByName (goodObjects [r]) in class;

    var newObject:MovieClip = new classRef();

    newObject.typestr = "good";

    } else

    {

    r = Math.floor (Math.random () * badObjects.length);

    classRef = getDefinitionByName(badObjects[r]) in class;

    newObject = new classRef();

    newObject.typestr = "bad";

    }

    gamesprite.addChild (newObject);

    newObject.x = Math.floor (Math.random () * stage.stageWidth);

    newObject.y = Math.floor (Math.random () * stage.stageHeight);

    break;

    }

    }

  • gotoAndplay from the instance on the stage to MovieClip in the library

    Hello

    I am trying to learn ActionScript 3. I have a MovieClip called ship in the library and made the class of so-called the ship. The ship movieClip shines the 6 Framework to indicate when he crashes into an asteroid.

    The child myShipMovieClip is controlled by the arrow keys and approaches asteroids. The hitTest works but I cannot get the ship to glow from the timeline to the MovieCli ship in the library and go to section 6 to begin to shine. I managed to do it in ActionScript 2 but have tried for the past few days attempting to do in AS3.

    Please can someone give me advice?

    Here is my code:

    import flash.events.KeyboardEvent;

    import flash.events.Event;

    import flash.display.MovieClip;

    var myShipMovieClip:MovieClip = new ship();

    addChild (myShipMovieClip);

    myShipMovieClip.x = 40;

    myShipMovieClip.y = 210;

    var myMovieClip:MovieClip = new asteroid();

    addChild (myMovieClip);

    myMovieClip.x = 500;

    myMovieClip.y = 210;

    addEventListener (Event.ENTER_FRAME, shipgo);

    function shipgo(e:Event):void

    {
    -myMovieClip.x;
    }

    var key_left:Boolean = false;

    var key_right:Boolean = false;

    var key_up:Boolean = false;

    var key_down:Boolean = false;

    stage.addEventListener (KeyboardEvent.KEY_DOWN, KeyDown);

    stage.addEventListener (KeyboardEvent.KEY_UP, KeyUp);

    addEventListener (Event.ENTER_FRAME, Main);

    function Main (event:Event)

    {

    CheckKeys();

    }

    function KeyDown(event:KeyboardEvent) {}

                    if(event.keyCode == 37) {}                            

                                    key_left = true;

                    }

                    if(event.keyCode == 39) {}                            

                                    key_right = true;

                    }

                    if(event.keyCode == 38) {}                            

                                    key_up = true;

                    }

                    if(event.keyCode == 40) {}                            

                                    KEY_DOWN = true;

                    }

    }

    function KeyUp(event:KeyboardEvent) {}

                    if(event.keyCode == 37) {}                            

                                    key_left = false;

                    }

                    if(event.keyCode == 39) {}                            

    key_right = false;

                    }

                    if(event.keyCode == 38) {}                            

                                    key_up = false;

                    }

                    if(event.keyCode == 40) {}                            

                                    KEY_DOWN = false;

                    }

    }

    function CheckKeys()

    {

    {if (key_left)}

    myShipMovieClip.x-= 5;

                    }

    {if (key_right)}

    myShipMovieClip.x += 5;

                    }

                    If (key_up) {}

    myShipMovieClip.y-= 5;

                    }

    {if (key_down)}

    myShipMovieClip.y += 5;

                    }

    }

    myMovieClip.addEventListener (Event.ENTER_FRAME, shipHit);

    function shipHit(event:Event):void

    {

    if (myMovieClip.hitTestObject (myShipMovieClip))

                    {

    this.removeChild (myMovieClip);

    myMovieClip.removeEventListener (Event.ENTER_FRAME, shipHit);

    myShipMovieClip.Ship.gotoAndPlay (6)

                    }

                    else

                    {

                    }

       }

    Try:

    import flash.events.KeyboardEvent;

    import flash.events.Event;

    import flash.display.MovieClip;

    var myShipMovieClip:MovieClip = new ship();

    addChild (myShipMovieClip);

    myShipMovieClip.x = 40;

    myShipMovieClip.y = 210;

    var myMovieClip:MovieClip = new asteroid();

    addChild (myMovieClip);

    myMovieClip.x = 500;

    myMovieClip.y = 210;

    addEventListener (Event.ENTER_FRAME, shipgo);

    function shipgo(e:Event):void

    {
    -myMovieClip.x;
    }

    var key_left:Boolean = false;

    var key_right:Boolean = false;

    var key_up:Boolean = false;

    var key_down:Boolean = false;

    stage.addEventListener (KeyboardEvent.KEY_DOWN, KeyDown);

    stage.addEventListener (KeyboardEvent.KEY_UP, KeyUp);

    addEventListener (Event.ENTER_FRAME, Main);

    function Main (event:Event)

    {

    CheckKeys();

    }

    function KeyDown(event:KeyboardEvent) {}

    if(Event.keycode == 37) {}

    key_left = true;

    }

    if(Event.keycode == 39) {}

    key_right = true;

    }

    if(Event.keycode == 38) {}

    key_up = true;

    }

    if(Event.keycode == 40) {}

    Key_Down = true;

    }

    }

    function KeyUp(event:KeyboardEvent) {}

    if(Event.keycode == 37) {}

    key_left = false;

    }

    if(Event.keycode == 39) {}

    key_right = false;

    }

    if(Event.keycode == 38) {}

    key_up = false;

    }

    if(Event.keycode == 40) {}

    Key_Down = false;

    }

    }

    function CheckKeys()

    {

    {if (key_left)}

    myShipMovieClip.x-= 5;

    }

    {if (key_right)}

    myShipMovieClip.x += 5;

    }

    {if (key_up)}

    myShipMovieClip.y-= 5;

    }

    {if (Key_Down)}

    myShipMovieClip.y += 5;

    }

    }

    myMovieClip.addEventListener (Event.ENTER_FRAME, shipHit);

    function shipHit(event:Event):void

    {

    If (myMovieClip.hitTestObject (myShipMovieClip))

    {

    this.removeChild (myMovieClip);

    myMovieClip.removeEventListener (Event.ENTER_FRAME, shipHit);

     myShipMovieClip.gotoAndPlay (6)

    }

    on the other

    {

    }

    }

  • Can I use the delete button to remove photos from the library (that is, any computer) when I'm in the album view?

    I like to use the album view to find the photos I don't want and it is easy to just hit delete. However, these pictures are just removed from the album, not the library. Configure the delete key to delete these photos of the whole library instead?

    Hold down the command key by pressing the button Delete. Then the picture will be deletedd and not just removed the library.

  • Button inside a clip controlling the main timeline

    Hello-

    I have a clip on the main stage - inside that movie clip is a button - I want that button to contol a function on the main timeline.

    example: the Script button

    closeAll_btn.addEventListener (MouseEvent.MOUSE_DOWN, goCloseAll);

    function goCloseAll(e:MouseEvent):void {}


    * do not know what to put here to activate "closeAllOpenMovieClips" on the main stage *


    }

    example: main stadium Timeline Script

    function closeAllOpenMovieClips (): void {}
    trek_mc.gotoAndStop (1);
    lost_arts_mc.gotoAndStop (1);
    rain_mc.gotoAndStop (1);
    vintage_mc.gotoAndStop (1);
    }


    do not know if I need a script more on chronology of main stadium that comes "from function."

    Thank you - Ben L

    If the button is in part 2, then the event listener so that it must be well on frame 2... or you could make the button visible/invisible betrween frames 1 and 2).

    But if you want to head back to your original approach...

    closeAll_btn.addEventListener (MouseEvent.MOUSE_DOWN, goCloseAll);

    function goCloseAll(e:MouseEvent):void {}

    MovieClip (root) .closeAllOpenMovieClips ();

    }

Maybe you are looking for

  • Satellite R830-146 - RAM upgrade

    I want to upgrade RAM, I can installDDR3 2 x 8 or only 2 x 4 DDR3? and who will be better?DDR3 1333 (PC-10600)orDDR3 1600 (PC-12800)

  • Satellite M60/M55: Turns off after power loss

    Reposting because the original threads are locked. http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=15285&MessageID=55746My M60 sometimes turns off immediately after unplugging the power supply (AC power or plug the laptop CC),

  • Waveform on F5 Sony... I can't find!

    Hi, looking for the signal and the histogram on my f5, can someone point me in the direction, all I can find is an assignable keys up/down key?

  • Error loading C:\WINNT\system32\iwosxftx.dll

    Whenever I turned on my Windows 200 Pro, you'll see this message at startup (click the link for the photo). Click Ok will return to the screen. But is it a problem and how to solve? http://ImageShack.us/photo/my-images/259/img4995b.jpg/

  • Cannot install updates of the Windows Defender definitions

    When I try to install definition updates, I get the following code: 0 x 80070643.  Help, please.  Thank you