A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS2 to AS3 simple navigation (undefined var)

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    7

    AS2 to AS3 simple navigation (undefined var)

    Hey,
    Having a problem with basic navigation in a 'Captivate' bound project I'm trying to create.
    I'm using the same methods/code I've used with other AS2 projects I�ve created in the past and tried to update it to AS3 but I keep getting errors.

    The project/nav.fla -
    I've two Content MCs based in the main/root timeline, that contain four sections in each and I'm trying to create a back button that will take the user from the start of the second MC to the end of the first MC, (hope that makes sense) so not to break the back button.
    I've declared a var in the root:

    var contentBk:Boolean = false;


    Then on the back button in the second MC, I change the root contentBk var to true:

    btnBackCont1.addEventListener(MouseEvent.CLICK, btnBkCont1Clicked);
    function btnBkCont1Clicked(event:MouseEvent):void
    {
    MovieClip(parent).gotoAndPlay("Content");
    MovieClip(parent).contentBk = true;
    trace(MovieClip(parent). contentBk);
    }


    And I've used a conditional 'if' statement the in the first frame of the fist MC to move the movie to the last section of the first MC when the back button is pressed:

    if (MovieClip(parent).contentBk == true)
    {
    gotoAndPlay("Section4");
    } else {

    }

    This is the code I've used before AS2 and it works, but now AS3 keeps throwing up an error and I don't know why, In my head the logic is sound and this should work! Sigh.
    Sorry Guys, I know this is basic AS3 stuff but any help would really be appreciated.

    I'm using CS5.
    Attached Files Attached Files
    Last edited by russ74; 11-22-2012 at 06:01 AM.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    That has probably to do with the fact that content1 is framewise separated from the frame where your Boolean var is defined. Working with frames is not to recommend and causes all kinds of problems. To get by this problem you have several choices:

    var myContentBk:Boolean = MovieClip(parent).contentBk;
    btnBackCont1.addEventListener(MouseEvent.CLICK, btnBkCont1Clicked);
    function btnBkCont1Clicked(event:MouseEvent):void
    {
    var forBack:MovieClip=event.currentTarget.parent.root as MovieClip;// main timeline
    forBack.gotoAndPlay("Content");
    myContentBk = true;
    //forBack.contentBk = true;// is also possible
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Hey Cancerinform,

    Big thanks for taking the time to rely and for the help.

    If you've got the time could you suggest an alternative to using frames?

    I remember many moons ago...in my MX days using 'Scenes', but remember having issues with that also.

    The application that I'm building is for 'Captivate' and is going to contain lots of embedded 3d rendered video, so the timeline could run into hundreds of frames, hence reason for trying to break up the MC's into smaller more manageable timelines.

    So could you suggest a more efficient method for creating such an application?

    You can probably tell It's been a while since i've used Flash.

    Cheers

    Russ

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Use classes and OOP. Start with a Document class. Use Design Patterns like the Model-View-Controller. Especially when your movie becomes big and complicated it is important to take the time in the beginning to set it up or as in your case to learn some things first. Animations can be done with AS rather using frames. Also videos should not be embedded. There are tons of tutorials out there when you need a certain effect or to learn something including the AS language reference.
    Frames are going to drive you crazy. They are only good if you pure animation with characters.

    Here is an example for basic AS3 OOP:
    http://flashscript.biz/flashas3/AS3_...roduction.html

    Here is an example for MVC model:
    http://flashscript.biz/flashas3/flas.../LoginMVC.html
    Last edited by cancerinform; 11-23-2012 at 09:36 PM.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Massive thanks cancerinform for taking the time to reply and the links which i'll defo look into.

    Nice One

    Russ.

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