A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Newbie question.

  1. #1
    noob in training
    Join Date
    May 2009
    Location
    Malaysia
    Posts
    23

    Newbie question.

    Hi there, I'm having some problems switching from As 2.0 to As 3.0. How to make a variable trigger. in As 3.0? Lets say i have this on my time-line.

    function onClick2(evt:MouseEvent):void{
    var pagenumber = "pg03";
    switch01.gotoAndStop("red");
    gotoAndPlay (2);
    }

    How do i make a mc gotoAndPlay (_root.pagenumber) like we do in As 2.0?

  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    6
    gotoAndPlay(MovieClip(root).pagenumber);

    or

    gotoAndPlay((root as MovieClip).pagenumber);

    Basically, AS3 wont assume that "root", "parent", etc. are MovieClips unless you tell it that they are.

  3. #3
    noob in training
    Join Date
    May 2009
    Location
    Malaysia
    Posts
    23
    Didn't Quite worked... "pg03" was a labeled frame inside a MC.

  4. #4
    Junior Member
    Join Date
    Jun 2009
    Posts
    6
    Hmmm.... Let me see if I understand you correctly:

    I'm assuming that pagenumber is a variable on your root timeline, and that you're putting this line:
    gotoAndPlay(MovieClip(root).pagenumber);
    into a function the timeline of your movieclip, that you're calling somehow.
    Sorry if that's not right...

    If it is, it could be that the function inside the movieclip is being called before pagenumber is being set - or that it's not being called at all. Did you want the MC to jump to "pagenumber" when the function you posted is run? If so, that's much easier:

    function onClick2(evt:MouseEvent):void{
    var pagenumber = "pg03";

    //add this line
    mc.gotoAndPlay(pagenumber);

    switch01.gotoAndStop("red");
    gotoAndPlay (2);
    }

    I hope that works. If not, let me know if I'm assuming the right things.
    Last edited by LunaJester; 06-02-2009 at 03:20 PM.

  5. #5
    noob in training
    Join Date
    May 2009
    Location
    Malaysia
    Posts
    23
    Its something similar, But it didn't worked right as well. Here is the link to the fla

    Thanks alot =D
    Last edited by ashed-dreams; 06-03-2009 at 09:24 AM.

  6. #6
    Junior Member
    Join Date
    Jun 2009
    Posts
    6
    Thanks for the file. It's much more clear now.

    The thing that seems to be tripping the code up is the declaration of pagenumber. In as3, if you declare a variable within a function, it only "counts" as a variable for that function (then is erased once it's done).
    It's an easy fix though, just declare it as a global variable by putting this:

    var pagenumber:String = new String();

    at the very beginning of your code, then erase "var" from the uses of pagenumber in your functions (else, you'll be declaring it twice, which as3 doesn't allow). That should fix it. (And, sorry, I should have noticed that when I looked at the code above.)
    Also, I uploaded a version with changes made, in case that was less clear than I thought.
    Attached Files Attached Files
    Last edited by LunaJester; 06-03-2009 at 12:49 PM.

  7. #7
    noob in training
    Join Date
    May 2009
    Location
    Malaysia
    Posts
    23
    Thank you very much :worship:

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