dcsimg
A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: [RESOLVED] Not understanding this array issue.

  1. #1
    Member
    Join Date
    Sep 2007
    Posts
    65

    resolved [RESOLVED] Not understanding this array issue.

    On my stage, I have a navigation bar "navbar_mc". In a seperate AS file, I reference this bar to add event listeners, as such:

    navbar_mc.navcont_mc.navcont_btn.addEventListener( MouseEvent.CLICK, contactingPage);
    However, when I use,

    var array:Array = new Array(navbar_mc.navcont_mc.navcont_btn);
    It gives me the following error:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Web::Website()
    Why can I assign even listeners to navbar_mc, but not assign it into an array?

  2. #2
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    Are you coding in AS2 or AS3?

  3. #3
    Member
    Join Date
    Sep 2007
    Posts
    65
    AS3? *Looks up*, this is the AS3 forum right?
    Last edited by simplexian; 04-24-2008 at 08:41 PM.

  4. #4
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    Yeah, I know the question looked kind of stupid but the notation you are using to get to nested clips is one that works with AS2.

    I'm not the expert yet in AS3 as I just started migrating from AS2 to AS3 myself but to get to nested clips, you need to go through the display list by using getChildByName() or similar functions.

    I believe that this is your error and not the array in itself.

  5. #5
    Member
    Join Date
    Sep 2007
    Posts
    65
    For example, when I use...

    var displaylist:Array = New Array();

    function...

    displaylist.push(navbar_mc.navcont_mc.navcont_btn) ;
    trace(displaylist[0].name);
    It works, being that it stores the button in the array as intended.
    But when I use...

    var displaylist:Array = new Array(navbar_mc.navcont_mc.navcont_btn)
    ... I'm given the error I stated in my first post. I'm trying to understand why this method is failing?
    Last edited by simplexian; 04-24-2008 at 10:53 PM.

  6. #6
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    Hi,

    I tried exactly what you mentionned and never got any warnings. Actually, it worked perfectly.

    I guess, if you need more help, maybe you should post your fla or a sample that does not work.

    Sorry!

  7. #7
    Member
    Join Date
    Sep 2007
    Posts
    65
    I'll post it up, sec.

  8. #8
    Member
    Join Date
    Sep 2007
    Posts
    65
    Won't let me upload an .as file from this site, have an email address I can send it to?
    Last edited by simplexian; 04-24-2008 at 11:26 PM.

  9. #9
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    I sent you a PM with my e-mail address. Was planning to go to bed. Do you need that urgently tonight?

  10. #10
    Member
    Join Date
    Sep 2007
    Posts
    65
    Try that.
    Last edited by simplexian; 04-24-2008 at 11:39 PM.

  11. #11
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    Got it, will take a few minutes to see if I see something wrong.

  12. #12
    Member
    Join Date
    Sep 2007
    Posts
    65
    That's just a piece of it, but you should see what I am trying to accomplish there, but I can't seem to do it. I want to store the buttons from that navigation bar into an array in a seperate AS file.

    If you put
    navbar_mc.navhome_mc.navhome_btn.y = 100;
    within the public function Example, you'll see that I can reference the button from the AS file, but I can't seem to reference it from an array.
    Last edited by simplexian; 04-24-2008 at 11:43 PM.

  13. #13
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    It is like I said in the first post, you have to use getChildByName when you want to grab a clip from the stage from the main document class. Not to sure why.

    Try this code, it works:
    Code:
    package Web {
    	import flash.display.*;
    	public class Example extends Sprite {
    		var displayList:Array = null;
    		public function Example() {
    			var navBar:MovieClip = MovieClip(this.getChildByName("navbar_mc"));
    			displayList = new Array(navBar.navhome_mc.navhome_btn,
    								 navBar.navcont_mc.navcont_btn,
    								 navBar.navcont_mc.navcont_btn);
    			
    			trace("Ran");
    		}
    	}
    }
    Have fun!

  14. #14
    Member
    Join Date
    Sep 2007
    Posts
    65
    Whyves, you're the bomb. Thanks for helping me out with this, been driving me nuts all day. Night.

  15. #15
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    Can go to bed in peace now! Glad I could have helped!

  16. #16
    Senior Member
    Join Date
    Jan 2008
    Location
    Montreal
    Posts
    101
    Actually, it also works this way as well:

    Code:
    			displayList = new Array(navbar_mc.navhome_mc.navhome_btn,
    								    navbar_mc.navcont_mc.navcont_btn,
    								    navbar_mc.navcont_mc.navcont_btn);
    as long as it's in the Example function. It fails when you try to do that in the class body itself.

    Whyves

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