A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: 1120: Access of undefined property border.

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    129

    1120: Access of undefined property border.

    Hello,



    I was average at AS2 and now I'm moving on to AS3. I've just read the tutorials on here regarding Classes to get myself clued up, and it all makes a fair bit of sense.



    I'm attempting to make my first Flash that uses an external .as file. However, I can't see why I'm getting the error message shown in the title of this thread.



    Here's the relevant code in my timeline:



    Code:
     
    
    // Button functions
    
    var buttonScript:Buttons = new Buttons();
    
    // Button events
    
    border.skip_intro_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
    
    border.skip_intro_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
    
    border.skip_intro_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
    
    border.main_menu.home_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
    
    border.main_menu.home_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
    
    border.main_menu.home_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
    
    border.main_menu.trailer_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
    
    border.main_menu.trailer_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
    
    border.main_menu.trailer_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
    
    border.main_menu.shop_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
    
    border.main_menu.shop_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
    
    border.main_menu.shop_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
    
    border.main_menu.contact_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
    
    border.main_menu.contact_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
    
    border.main_menu.contact_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);


    And here's the code from the .as file:



    Code:
    package {
    
     import flash.display.*; 
    
        import flash.events.*; 
    
     public class Buttons extends MovieClip {
    
      public var buttonsActive = true;
    
      function Buttons() {
    
      }
    
      public function buttonDimmer(evt:MouseEvent):void {
    
       if (buttonsActive == true) {
    
        evt.target.buttonMode = true;
    
        evt.target.useHandCursor = true;
    
        evt.target.gotoAndPlay("rollover");
    
       }
    
      }
    
      public function buttonLighter(evt:MouseEvent):void {
    
       if (buttonsActive == true) {
    
        evt.target.gotoAndPlay("rollout");
    
       }
    
      }
    
      public function jumpToPage(evt:MouseEvent):void {
    
       if (buttonsActive == true) {
    
        if (evt.target == border.skip_intro_btn) {
    
         border.gotoAndPlay("buttons change");
    
         gotoAndStop("home");
    
        } else if (evt.target == border.home_btn) {
    
         gotoAndStop("home");
    
        } else if (evt.target == border.trailer_btn) {
    
         gotoAndStop("trailer");
    
        } else if (evt.target == border.shop_btn) {
    
         gotoAndStop("home");
    
        } else if (evt.target == border.contact_btn) {
    
         gotoAndStop("home");
    
        }
    
       }
    
      }
    
     }
    
    }


    All of this code worked before I packaged it into an .as file.



    I'd appreciate it if anyone could tell me why this is happening, but I'd also be very grateful if people could give me feedback on if I'm using this class for the right sort of thing. If all this kind of code would be better suited in the timeline, or if I'm just plain doing things incorrectly, please inform me!



    Thanks!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You have to declare the variable first:
    public var border:MovieClip (if it is a movieclip)
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Thank you very much, that got rid of that error.

    However, when clicking on skip_intro_btn, I get the following error:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Buttons/jumpToPage()

    Which must be referring to this chunk of code:

    Code:
    public function jumpToPage(evt:MouseEvent):void {
    			if (buttonsActive == true) {
    				if (evt.target == menuBorder.skip_intro_btn) {
    					menuBorder.gotoAndPlay("buttons change");
    					gotoAndStop("home");
    				} else if (evt.target == menuBorder.home_btn) {
    					gotoAndStop("home");
    				} else if (evt.target == menuBorder.trailer_btn) {
    					gotoAndStop("trailer");
    				} else if (evt.target == menuBorder.shop_btn) {
    					gotoAndStop("home");
    				} else if (evt.target == menuBorder.contact_btn) {
    					gotoAndStop("home");
    				}
    			}
    		}
    I don't understand! An explanation and fix would be greatly appreciated

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    If you get such error use trace actions
    trace(menuBorder.skip_intro_btn);
    for example.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Thanks again for your quick response.

    I put the trace in the main timeline, and I get this result:

    [object skipintrobutton_6]

    What does that mean? Also, when I put the trace in the .AS file, nothing happened.

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    That means the object is defined and you need to check other objects. If any of them is defined you would get null. If you get nothing, the error has occurred earlier. Place it at different positions.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Having looked back at the initial problem, was declaring "menuBorder" as a public variable in my .as file the best thing to do? Isn't it already on my stage? Shouldn't it have been declared as a variable in the timeline, rather than in my Buttons class?

    I only ask because I don't understand the logic of AS3 yet.

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yes, you need to reference the same border instance that is on the stage. You can declare a variable for that in the Buttons class, but you need to set that variable to the right instance.

    If your Buttons instance is on the displayList, and border is a direct child of the root, you should be able to set the menuBorder variable in Buttons like this:
    Code:
    menuBorder = root.getChildByName("menuBorder");
    But this must be done after Buttons is added to the display list. Putting that line inside jumpToPage should be fine, but in that case I'd suggest making the variable local to the function instead of class level.

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