Skip to main content
Known Participant
April 25, 2019
Answered

bring to front mc

  • April 25, 2019
  • 1 reply
  • 821 views

i need certain mc to be brought to front of stage upon clicking on a button, and then instruct that mc to go to frame 2 and play.

thanks

    This topic has been closed for replies.
    Correct answer kdmemory

    thank you however it still doest work

    can you help?

    this is my script:

    import flash.events.TimerEvent;

    import flash.events.TouchEvent;

    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

    kfir1.addEventListener(TouchEvent.TOUCH_BEGIN, bgn);

    kfir1.addEventListener(TouchEvent.TOUCH_END, stp);

    var fl_DragBounds_10:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

    function bgn(event:TouchEvent):void

    {

    event.currentTarget.startTouchDrag(event.touchPointID, false, fl_DragBounds_10);

    }

    function stp(event:TouchEvent):void

    {

    event.currentTarget.stopTouchDrag(event.touchPointID);

    if (kfir1.hitTestObject(lion))

    {

    lion.gotoAndPlay(2)

    parent.setChildIndex(lion,1);

    kfir1.visible=0

    }

    }

    ‫ב-26 באפר׳ 2019, בשעה 4:33 אח׳, ‏‏⁨resdesign⁩ ‏<⁨forums_noreply@adobe.com<mailto:forums_noreply@adobe.com>⁩> כתב/ה:‬

    bring to front mc

    created by resdesign<https://forums.adobe.com/people/resdesign> in Adobe Animate - View the full discussion<https://forums.adobe.com/message/11047815#11047815>


    Hi udik

    Detect the number of children of the parent container of your event.currentTarget in order to set the highest possible childindex.

    Your stp function:

    function stp (event:TouchEvent):void {

        event.currentTarget.stopTouchDrag(event.touchPointID);

        if (kfir1.hitTestObject(lion)) {

            lion.gotoAndPlay(2)

            parent.setChildIndex(lion,1);

            kfir1.visible = 0

        }

    }

    I'm not sure about your event context (Multitouch.inputMode), but things can't work this way. Mainly setting the setChildIndex for the lion just to 1 puts it in the stacking order of the child array into the second lowest position. To set the lion (in this case) to the top position, find out how many children there are in the parent container and set the lion to the top of the range.

    My suggestion for the stp function:

    function stp (event:TouchEvent):void {

        var hiIdx: int; /* to hold numChildren-1 =/= highest occupied index */

        var ect = event.currentTarget;

        ect.stopTouchDrag(event.touchPointID);

        if (kfir1.hitTestObject(lion)) {

            ect.gotoAndPlay(2);

            // -----------------------------------------

            hiIdx = ect.parent.numChildren - 1;

            ect.parent.setChildIndex(event.target,hiIdx);

            // -----------------------------------------

            kfir1.visible = false;

        }

    }

    hope it helps

    Klaus

    1 reply

    avid_body16B8
    Legend
    April 25, 2019

    AS3 or HTML5?

    udikAuthor
    Known Participant
    April 26, 2019

    As3

    thanks

    avid_body16B8
    Legend
    April 26, 2019

    If the movieclips are on the same layer, you can change their z-index position like this

    Put the code in your mouse event.

    parent.setChildIndex(yourMovieClipName, i)