-1

How to with "addchild(page2)" animate showing with Tweening!

This is my simple class of actionscript to make that,MovieClip did not play animation when using addChild(), do you have any suggestions?

my page1..3 are MovieClips!

package
{

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.TouchEvent;

    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

    public class Main extends MovieClip
    {
        var page1: Page1;
        var page2: Page2;
        var page3: Page3;


        public function Main()
        {
            page1 = new Page1;
            page2 = new Page2;
            page3 = new Page3;
            addChild(page1);
            //


            //
            page1.clip2.addEventListener(TouchEvent.TOUCH_BEGIN, onClip2ButtonClick);
            page2.clip.addEventListener(TouchEvent.TOUCH_BEGIN, onClipButtonClick);
        }

        function onClipButtonClick(event: TouchEvent): void
        {
            addChild(page3);
            removeChild(page2);
        }

        function onClip2ButtonClick(event: TouchEvent): void
        {
            addChild(page2);
            removeChild(page1);
        }

    }

}

We Can by this tween and without programming

by tweening motion with frames, we can use multi effect. In this file fade effect uses for that, but can 3d effect and another..

S At
  • 422
  • 5
  • 15

2 Answers2

2

You've got the correct answer on your own. Just to err on the safer side, you should wait to receive an event before performing the transition or removing the object from the display list.

private function clip_touchBeginHandler(event:Event):void
{
    page1.addEventListener(Event.ADDED_TO_STAGE, page1_addedToStageHandler);
    addChild(page1);
}

private function page1_addedToStageHandler(event:Event):void
{
    var tm:TransitionManager = new TransitionManager(page1);
    var transition:Transition = tm.startTransition(...); // Add your transition parameters here
    transition.addEventListener("transitionInDone", transition_transitionInDone);
}

private function transition_transitionInDone(event:Event):void
{
    removeChild(page1);
}
Pranav Negandhi
  • 1,594
  • 1
  • 8
  • 17
  • thx, I've question. Because I am new to actionscript, several func is better than one func ? for do one perform!. when I've very pages e.g. 1...100. – S At Aug 25 '16 at 14:19
  • It's not about the functions themselves, but rather the event that occurs that triggers the function. Adding a movie clip to the stage might not occur immediately after the addChild method if the computer is slow. So you should always wait for the ADDED_TO_STAGE event before applying any transition to the object. You can refer to the article at http://www.emanueleferonato.com/2009/12/03/understand-added_to_stage-event/ to understand this model in more detail. – Pranav Negandhi Aug 25 '16 at 16:52
  • excuse me, another q, how to follow you in stackoverflow? – S At Aug 25 '16 at 18:34
1

We try and got it. By add this code in our class.

function onClipButtonClick(event: TouchEvent): void
            {
                addChild(page1);
                var myTM: TransitionManager = new TransitionManager(page1);
                myTM.startTransition(
                {
                    type: Fly,
                    direction: Transition.IN,
                    duration: 3,
                    easing: Back.easeOut
                })

                removeChild(page2);
            }
S At
  • 422
  • 5
  • 15