Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    HI :classic:

    I have a question, I have an array pre-filled with certain state names, these state names will differ each time. But nevertheless, this array is already afilled and the array is

    Code:
     loadXML.stateNames
    I have US States in a MovieClip that have instance names as their abbreviations (i.e., PA, AL, etc). I am trying to get all these US States names from the array (code below) and make their names into the Event Listeners so as to save memory if for example only 25 US States are required. I don't want their to be 52 Event Listeners every time the file is run. I can't seem to figure out how to get their names from the Array and make it into an event listener. Any ideas???


    Code:
    function onArrayComplete(e:Event):void	// state click event handlers
    {
    	for (var i:uint = 0; i < loadXML.stateNames.length; i++)
    	{
    		     mapUSA. + loadXML.stateNames[i] + .addEventListener(MouseEvent.CLICK, onClickMouse, false, 0, true);
    	}
    }

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    It looks like what you'd want to do is

    Code:
    mapUSA[loadXML.stateNames[i]].add...
    Keep in mind that the Right Way (tm) to do this is probably to add an event listener directly to the mapUSA clip. That cilp has mouse events bubbled up to it, so it will receive clicks from any of its children. You can then use the event.target parameter, which will be set to the particular movie clip that was clicked, to determine which state it was.

  4. #3
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    ok cool, will try this on monday. Thanks!

  5. #4
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Ok, i'm a little late on trying this. However, I did try it today (had other projects as priorities), and it does work indeed. The question I have though, is how does it work?

    I mean, in my code

    var mapUSA is a the map of the US.

    then the state code, like PA is a movieclip inside of the mapUSA movieclip. So to manually add an event listener, I would do

    Code:
    mapUSA.PA.addEventListener(.......
    but here, we aren't even using the dot. So isn't it getting this

    Code:
    mapUSAPA.addEventListener(........

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    So I'm not 100% sure what you mean. What did you try, and what is unclear about it?

  7. #6
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Quote Originally Posted by Shadowfiend
    So I'm not 100% sure what you mean. What did you try, and what is unclear about it?

    i'm saying that I tried it and it works. Yet, I don't understand how it works....

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well yes, but I recommended two ways of trying it

    If you're talking about the mapUSA[loadXML.stateNames...] method, then the reason that works is that properties in ActionScript can be accessed both using array notation [] and using dot notation. So these two are equivalent:

    Code:
    mapUSA["PA"]
    mapUSA.PA
    That's just the way the language is built. Does that make sense?

  9. #8
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Quote Originally Posted by Shadowfiend
    Well yes, but I recommended two ways of trying it

    If you're talking about the mapUSA[loadXML.stateNames...] method, then the reason that works is that properties in ActionScript can be accessed both using array notation [] and using dot notation. So these two are equivalent:

    Code:
    mapUSA["PA"]
    mapUSA.PA
    That's just the way the language is built. Does that make sense?
    I undersatnd what you mean, yet the challenge I'm facing is that "PA" is a string, and a key in an array (myArray["PA"]). So how come I can access a string via mapUSA.PA ??

  10. #9
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    They are exactly equivalent. One converts to the other, and vice versa. As long as your key has no special characters, you can access it using dot notation. It doesn't matter if it's on an array or any other object.

  11. #10
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    ok cool. I did not know that. I thought you always had to access it as a string like array["val"]


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com