-
[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’ll give you a walkthrough of what I have.
Scene: contains a brief animation, a stop action at the end, and a MovieClip that I’ll call Menu.
Menu: contains a script layer and two MovieClips, one I’ll 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’m 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);
-
Can you post the actual Compiler Error Description and Source? That should help us help you.
-
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.
-
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)?
-
It is a button that I created. It is all one file.
-
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
-
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()
-
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.
-
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
-
Were you able to find out where the problem is using the Debugger?
-
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.
-
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.
-
Where would I place that exactly?
-
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.
-
Okay, I get output: Rolled Over.
function main1Over(event:MouseEvent):void {
gotoAndPlay("down1");
}
Navigation.btn1.addEventListener(MouseEvent.ROLL_O VER, main1Over);
-
Try changing gotoAndPlay("down1"); to down1.play();
-
also, if it is inside your movie clip, you will have to do my_mc.down1.play(); like you did to the buttons.
-
TypeError: Error #1010: A term is undefined and has no properties.
at Opening_fla::Menu_25/main4Over()
-
Did you run the debugger?
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|