A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: How to reference MovieClip in certain frame?

  1. #1
    Junior Member
    Join Date
    Jul 2015
    Posts
    8

    How to reference MovieClip in certain frame?

    I have a MC in Scene1 frame 5, let's call it Mc_A. There's a button (Btn_A) inside Mc_A, the eventListener for the button goes to MovieClip(root).gotoAndstop("Pg_Name1").

    Pg_Name1 is frame 10 in Scene 1. There's a MovieClip on this frame too, Mc_B.

    I want to be able to click on Btn_A and have it go to Pg_Name1 but also gotoAndStop on frame 9 of Mc_B.

    I can't figure out the syntax because Mc_B is not on all the frames, so I keep getting a reference error on Bfn_A.

    Any help would be great. How do I reference a MovieClip that's on a specific frame on scene 1?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I don't think you can as it doesn't exist until you reach that frame.

    You can however use addchild/removechild or use clip.visible true /false, maybe even just using one frame with this method.

    you could also declare the movieclip var at the beginning and use something like - if(clip){//whatever)

  3. #3
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    Quote Originally Posted by fruitbeard View Post
    Hi,

    I don't think you can as it doesn't exist until you reach that frame.

    You can however use addchild/removechild or use clip.visible true /false, maybe even just using one frame with this method.

    you could also declare the movieclip var at the beginning and use something like - if(clip){//whatever)
    Oh darn, that makes sense. How would I go about doing the child method? Sorry I'm a bit New and I'm learning through the internet.

  4. #4
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    Actually, I think I could just use an Enter_Frame event listener, once I get to the Pg_Name1 to look for a variable.
    Only, I don't know how to make a "constant" variable that works for the whole scene 1. Does anyone know how?

    What if say I made VarPg = Integer, then when I clicked on Btn_A, it goes to Pg_Name1 AND makes VarPg = 1.
    Then when it loads Pg_Name1 there's an Enter_Frame eventListener with an if(VarPg == 1){Mc_B.gotoAndStop(9);}

    Do you know how and where I can put a customizable variable that works for the whole scene?
    I tried putting it a top layer that had a frame all the way through, but I don't know the syntax to make it work.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    If I read you correctly then you will need to do something like so.

    Declare the clip in the first frame along with the other vars etc etc.

    var clip:MovieClip;
    var varPG:Number = 1;

    using your ENTER_FRAME listener that you have set up, listen for
    PHP Code:
    if (clip)
    {
        if (
    varPG == 1)
        {
            
    // varPG= 0; // prevent enterframe loop for this code
            // Do something code
        
    }

    in time though you might start just using one frame for your whole project, excluding animation clips and things.
    Last edited by fruitbeard; 08-01-2015 at 03:27 AM.

  6. #6
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    Quote Originally Posted by fruitbeard View Post
    Hi,

    If I read you correctly then you will need to do something like so.

    Declare the clip in the first frame along with the other vars etc etc.

    var clip:MovieClip;
    var varPG:Number = 1;

    using your ENTER_FRAME listener that you have set up, listen for
    PHP Code:
    if (clip)
    {
        if (
    varPG == 1)
        {
            
    // varPG= 0; // prevent enterframe loop for this code
            // Do something code
        
    }

    in time though you might start just using one frame for your whole project, excluding animation clips and things.
    Thank you, how do the variables work? I don't have to put them into a function or anything?
    Just put that straight onto the frame?

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I believe it will go inside of your ENTER_FRAME function handle.
    I am not sure how you are creating you varPg var though or where and how you are creating the ENTER_FRAME function you have made.

  8. #8
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    Okay so, I hope I can explain this properly, I'm so close. Next time I'll definitely use your suggestion of one clip, but I'm in too deep now, ha. Here's an example (not real frame names or frame numbers) of what I've got going so far:

    Frame 1 > There's two layers;
    Layer 1 (top layer) is the ActionScript.
    PHP Code:
    Btn_A.addEventListener(MouseEvent.CLICKgotoF9);
    function 
    gotoF9(event:MouseEvent):void{
        
    //This is what I don't know how to write:
        //var varPg = 2;
        
    gotoAndStop(9);

    Layer 2 there's a MovieClip.
    Inside the MC is a button (Btn_A).

    Frame 9 > There's two layers;
    Layer 1 (top layer) is the Action Script.
    PHP Code:
    addEventListener(Event.Enter_FramecheckBtn);
    function 
    checkBtn(event:Event):void{
        
    //if(varPG == 2){
            
    Mc_Act.gotoAndStop(2);
        
    //}

    Layer 2 there's a MovieClip (Mc_Act).

    My problem is that the If statement in frame 9 either; doesn't know what the varPg is or doesn't recognize it. I tested the function checkBtn without the If statement, and it works. When I tried:
    PHP Code:
    addEventListener(Event.Enter_FramecheckBtn);
    function 
    checkBtn(event:Event):void{
        
    trace(varPg);

    All it did was give me back a value of NaN.

    What I want to do is make a button on frame 1 that will change the frame of a movie clip that's on frame 9. The reason for this is that there are multiple buttons on frame 1 that will dictate which frame the movie clip (that's located on frame 9) should start on.
    Last edited by WarriorDex84; 08-02-2015 at 12:19 PM.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Attach your *.fla, that is too confusing for me to try and make a mock up example.

    you haven't declared varPg according to the bits of code you supplied.

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    maybe this might help you along

  11. #11
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    Quote Originally Posted by fruitbeard View Post
    Hi,

    maybe this might help you along
    It says the "Unexpected File Format" and closes.
    I'm using CS4.

    I think I figured out what the problem is though. You're a genius, you triggered a thought.

    The "var is not defined"!

    I just realized that my first code was inside a particular keyframe in the first MovieClip, so by the time I was able to get to frame 9, the var was no longer valid because the MC with the keyframe that has the AS no longer exists in frame 9.

    I really appreciate you're desire to help and you've been very great, but the file I'm making right now has sensitive information from my work, so I can't send out the file yet. One thing I could use though: how do you reference a MovieClip on only one particular frame?

    Like if I had a MC on frame 9, and there's a MC just on frame 9. Normally I would write something like:
    PHP Code:
    MovieClip(root).Mc_A.gotoAndStop(2); 
    but if the Mc_A is only on frame 3 how do I reference that? I tried MovieClip(3, root).Mc_A.gotoAndStop(2); and it didn't work.

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Just put the code on the same frame as the clip and have it say something like clip.gotoAndStop(varPg);
    varPg will have been assigned a value from one of the buttons that sent it to this frame.

    But without really knowing how you have your set up it's hard to clarify it, you could make a smaller similar set up file and attach it if the project you are working on is so so sensitive.

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