A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Delay Adding Child (Movie Clip) to Stage

  1. #1
    Member
    Join Date
    Nov 2007
    Location
    Los Angeles, CA
    Posts
    32

    Delay Adding Child (Movie Clip) to Stage

    I am attempting to add a movie clip to the stage when a button is triggered. When the user clicks the button the movie clip is added to the stage; it works fine, but the following problems occur:

    1) The appearance of the movie clip is delayed.
    2) The sound in the movie clip starts to play but the movie clip appears when the sound is finished.

    Additional information:
    1) The movie clip has the sound in the timeline.

    Here is the code:

    Actionscript Code:
    //Buttons: Adds movie clip to stage.
    readtomeShortA1.addEventListener(MouseEvent.CLICK, playShortAReadMe1);

    var playShortA1:ShortAReadMe1

    function playShortAReadMe1(e:MouseEvent):void{
        playShortA1 = new ShortAReadMe1
        addChild(playShortA1);
        playShortA1.x = 307;
        playShortA1.y = 603;

    }


    My questions are:

    1) I'm not sure if the movie clip is playing or not. The movieclip is supposed to play on top of a text box. It is the same text, but the movieclip text highlights the words as it is being played.

    So the movieclip may be playing but under the other layers. I suspect this is the problem. If so, then I would assume I would use the addChildat method so that the movieclip plays on top. Please confirm. Note I did this with the following code and I was still not able to see the movie clip. I was attempting to have the movieclip play on top of everthing:

    Actionscript Code:
    function playShortAReadMe1(e:MouseEvent):void{
        playShortA1 = new ShortAReadMe1
        addChildAt(playShortA1,7);
        playShortA1.x = 307;
        playShortA1.y = 603;
        trace (numChildren);

    }


    2) However, I also want to know is keeping the sound in the timeline of the movieclip the most efficient way to use sound in the movieclip? Or is there better, more efficient way to do it? I ask this because I want to make sure that there are no problems with the sound being loaded when called.

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    5
    Hi, I'm a newbie and Flash but I think I have a solution on your Problem.

    If the Sound of your Movie is inside the MovieClip; this will do.

    First, you may Want to put a stop(); on your MovieClip if the button that will trigger to play it is not clicked.

    Second, if the Button that will trigger to play the MovieClip is Clicked, the MovieClip should play.

    or if you want to have the MovieClip being Hidden.

    Here's a Quick Code:

    Actionscript Code:
    MovieClip.visible = false;
    MovieClip.stop();
    Button.addEventListener(MouseEvent.CLICK, buttonClick);

    function buttonClick(evt:MouseEvent):void {
    MovieClip.visible = true;
    MovieClip.x = 307;
    MovieClip.y = 603;
    MovieClip.play();
    }

    I hope it will help you. I only imagined it so You might Get the idea of the code i've provided instead of copying it and pasting it. ^^

  3. #3
    Member
    Join Date
    Nov 2007
    Location
    Los Angeles, CA
    Posts
    32
    Thanks. I'll try it and let you know.

  4. #4
    Member
    Join Date
    Nov 2007
    Location
    Los Angeles, CA
    Posts
    32
    Your method worked. However, the code was not the issue.

    I found that the movie clip was playing but it was off stage. When I created the movie clip I did not set the x and y coordinates to 0,0. Once they were set to 0,0 in the movie clip, they showed at the proper place on stage.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center