A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: [RESOLVED] AS3 Noob Please Help

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    21

    resolved [RESOLVED] AS3 Noob Please Help

    I have done many projects in ActionScript 2, but now I am creating a website in ActionScript 3.0. I値l give you a walkthrough of what I have.

    Scene: contains a brief animation, a stop action at the end, and a MovieClip that I値l call Menu.

    Menu: contains a script layer and two MovieClips, one I値l call Pages and the other, Navigation.
    On the script layer we have MouseEvent.CLICK and MouseEvent.ROLL_OVER for each button inside of Navigation.
    The MouseEvent.CLICK animates labels in Pages.
    The MouseEvent.ROLL_OVER animates labels in Navigation.
    Also, there is a stop action.

    Pages: contains each page appearance, labels to point to each, and stop actions to keep them separate.

    Navigation: contains the buttons (btn1, btn2, btn3, and btn4), each ROLL_OVER animation, labels to point to each, and stop actions to keep them separate.

    The problem that I知 having is that I get undefined property errors for the buttons. Each button is named appropriately and instanced appropriately as far as I can tell.

    CLICK script:
    function mainBtn1Down(event:MouseEvent):void {
    pages.gotoAndPlay("page1");
    }
    function mainBtn2Down(event:MouseEvent):void {
    pages.gotoAndPlay("page2");
    }
    function mainBtn3Down(event:MouseEvent):void {
    pages.gotoAndPlay("page3");
    }
    function mainBtn4Down(event:MouseEvent):void {
    pages.gotoAndPlay("page4");
    }
    btn1.addEventListener(MouseEvent.CLICK, mainBtn1Down);
    btn2.addEventListener(MouseEvent.CLICK, mainBtn2Down);
    btn3.addEventListener(MouseEvent.CLICK, mainBtn3Down);
    btn4.addEventListener(MouseEvent.CLICK, mainBtn4Down);

    ROLL_OVER script:
    function main1Over(event:MouseEvent):void {
    gotoAndPlay("down1");
    }
    function main2Over(event:MouseEvent):void {
    gotoAndPlay("down2");
    }
    function main3Over(event:MouseEvent):void {
    gotoAndPlay("down3");
    }
    function main4Over(event:MouseEvent):void {
    gotoAndPlay("down4");
    }
    btn1.addEventListener(MouseEvent.ROLL_OVER, main1Over);
    btn2.addEventListener(MouseEvent.ROLL_OVER, main2Over);
    btn3.addEventListener(MouseEvent.ROLL_OVER, main3Over);
    btn4.addEventListener(MouseEvent.ROLL_OVER, main4Over);

  2. #2
    Member
    Join Date
    Dec 2009
    Posts
    84
    Can you post the actual Compiler Error Description and Source? That should help us help you.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    Symbol 'Menu',Layer 'mnuAction', Frame 1, Line 33
    btn1.addEventListener(MouseEvent.CLICK, mainBtn1Down);
    1120: Access of undefined property btn1.

    Symbol 'Menu',Layer 'mnuAction', Frame 1, Line 34
    btn2.addEventListener(MouseEvent.CLICK, mainBtn2Down);
    1120: Access of undefined property btn2.

    Symbol 'Menu',Layer 'mnuAction', Frame 1, Line 35
    btn3.addEventListener(MouseEvent.CLICK, mainBtn3Down);
    1120: Access of undefined property btn3.

    Symbol 'Menu',Layer 'mnuAction', Frame 1, Line 36
    btn4.addEventListener(MouseEvent.CLICK, mainBtn4Down);
    1120: Access of undefined property btn4.
    --------------------------------------------
    Symbol 'Menu',Layer 'mnuScript', Frame 1, Line 14
    btn1.addEventListener(MouseEvent.ROLL_OVER, main1Over);
    1120: Access of undefined property btn1.

    Symbol 'Menu',Layer 'mnuScript', Frame 1, Line 15
    btn2.addEventListener(MouseEvent.ROLL_OVER, main2Over);
    1120: Access of undefined property btn2.

    Symbol 'Menu',Layer 'mnuScript', Frame 1, Line 16
    btn3.addEventListener(MouseEvent.ROLL_OVER, main3Over);
    1120: Access of undefined property btn3.

    Symbol 'Menu',Layer 'mnuScript', Frame 1, Line 17
    btn4.addEventListener(MouseEvent.ROLL_OVER, main4Over);
    1120: Access of undefined property btn4.

  4. #4
    Member
    Join Date
    Dec 2009
    Posts
    84
    Is this a button that is provided from Flash (ie var btn1:Button = new Button() or is this a button that you have created?

    Also, is all of your code in one .fla/.swf or are you using external packages (ie .as files)?

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    It is a button that I created. It is all one file.

  6. #6
    Member
    Join Date
    Dec 2009
    Posts
    84
    I believe that your problem is that the buttons are inside a movie clip. Try this:
    Actionscript Code:
    my_mc.btn1.addEventListener(MouseEvent.ROLL_OVER, main1Over);
     // my_mc being the name of the navigation movie clip they are in

  7. #7
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    Alright, I put that all in and it fixed the CLICKs, but the ROLL_OVERs are still broken. Thanks for the input! That's one step closer to online.

    Let me specify. All the errors are gone as far as the Compiler. Now I have an Output of:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Opening_fla::Menu_25/frame1()

  8. #8
    Member
    Join Date
    Dec 2009
    Posts
    84
    Well, if you run the built in debugger, it should place an error next to the line that is causing the error. Best of luck to you.
    Last edited by dukeufan4; 02-23-2011 at 03:54 PM.

  9. #9
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    Will do. I'll see if I can figure it out for a bit. I'll probably be back.
    Last edited by Eberwolf; 02-23-2011 at 03:59 PM. Reason: Pointless Post

  10. #10
    Member
    Join Date
    Dec 2009
    Posts
    84
    Were you able to find out where the problem is using the Debugger?

  11. #11
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    It called to a line of code for a button I hadn't added yet, so I removed all of that code. Now it gives me no output or compiler errors, but the rollovers still don't play.

  12. #12
    Member
    Join Date
    Dec 2009
    Posts
    84
    Can you insert a trace statement in one of your ROLL_OVER functions? Something like trace("Rolled Over");. Just to make sure it is triggering the function.

  13. #13
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    Where would I place that exactly?

  14. #14
    Member
    Join Date
    Dec 2009
    Posts
    84
    you should have something somewhere that looks like this:

    Actionscript Code:
    function main1Over(ev:MouseEvent):void{
    //code
    //code
    }

    I would add it right after the function declaration.

    Actionscript Code:
    function main1Over(ev:MouseEvent):void{
    trace("Rolled Over");
    //code
    //code
    }

    Also, can you post the code for your main1Over function? There could be a problem in there too.

  15. #15
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    Okay, I get output: Rolled Over.

    function main1Over(event:MouseEvent):void {
    gotoAndPlay("down1");
    }
    Navigation.btn1.addEventListener(MouseEvent.ROLL_O VER, main1Over);

  16. #16
    Member
    Join Date
    Dec 2009
    Posts
    84
    Try changing gotoAndPlay("down1"); to down1.play();

  17. #17
    Member
    Join Date
    Dec 2009
    Posts
    84
    also, if it is inside your movie clip, you will have to do my_mc.down1.play(); like you did to the buttons.

  18. #18
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    TypeError: Error #1010: A term is undefined and has no properties.
    at Opening_fla::Menu_25/main4Over()

  19. #19
    Member
    Join Date
    Dec 2009
    Posts
    84
    Did you run the debugger?

  20. #20
    Junior Member
    Join Date
    Feb 2011
    Posts
    21
    Points to Navi.down1.play();

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