RE: [Flashcoders] Accessing an Associative Array
Actually you have an Object not an Array when you define your variable : var myarray = { text:Lorem ipsum }; is the same as var myarray:Object = new Object(); myarray.text = Lorem ipsum; but with Actionscript you can access objects with the array notaion [] var i:Number = 1; var myMC:String = movieClip+i; this[myMC]._x = 26; myarray[text] = Lorem Ipsum; instead of this.movieClip1._x = 26; myarray.text = Lorem Ipsum; If you really want an associative array, look at Jason's answer Otherwise keep on using the Object notation, but you will lack all the Array object specific methods Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andy Herrman Sent: 12 mars 2007 16:47 To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Accessing an Associative Array I think this is your problem: showPopup(myarray); You're passing showPopup a string with the value myarray, not the array. Remove the quotes and you should be good. -Andy On 3/12/07, Bill Abel [EMAIL PROTECTED] wrote: How do you access an associate array using a variable? Inside my function popup[text]; won't access the array. I can't find any information in the books I have Actionsript Cookbook and Actionscript for Flash MX. Anyone dealt with this before? // Define the text and titles for the popups var myarray = { text: Lorem ipsum dolor sit amet ... }; // Testing - this works! trace(myarray[text]); // Show the popup function showPopup(popup) { mainMap[popup].gotoAndPlay(on); mainMap[popup].label_title.text = popup[text]; // This doesn't work. trace(popup[text]); }; showPopup(myarray); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 2007-03-12 19:19 -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 2007-03-12 19:19 ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Accessing an Associative Array
Right - myArray[hello] = hi is the same as: myArray.hello = hi Depends on your coding preferences. Personally, I prefer Alain's suggestion of object dot-notation syntax: myArray.hello if the array's name is variable, then: this[myArray].hello Jason Merrill Bank of America Global Technology Operations Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Tuesday, March 13, 2007 9:58 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Accessing an Associative Array Actually you have an Object not an Array when you define your variable : var myarray = { text:Lorem ipsum }; is the same as var myarray:Object = new Object(); myarray.text = Lorem ipsum; but with Actionscript you can access objects with the array notaion [] var i:Number = 1; var myMC:String = movieClip+i; this[myMC]._x = 26; myarray[text] = Lorem Ipsum; instead of this.movieClip1._x = 26; myarray.text = Lorem Ipsum; If you really want an associative array, look at Jason's answer Otherwise keep on using the Object notation, but you will lack all the Array object specific methods Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andy Herrman Sent: 12 mars 2007 16:47 To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Accessing an Associative Array I think this is your problem: showPopup(myarray); You're passing showPopup a string with the value myarray, not the array. Remove the quotes and you should be good. -Andy On 3/12/07, Bill Abel [EMAIL PROTECTED] wrote: How do you access an associate array using a variable? Inside my function popup[text]; won't access the array. I can't find any information in the books I have Actionsript Cookbook and Actionscript for Flash MX. Anyone dealt with this before? // Define the text and titles for the popups var myarray = { text: Lorem ipsum dolor sit amet ... }; // Testing - this works! trace(myarray[text]); // Show the popup function showPopup(popup) { mainMap[popup].gotoAndPlay(on); mainMap[popup].label_title.text = popup[text]; // This doesn't work. trace(popup[text]); }; showPopup(myarray); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 2007-03-12 19:19 -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 2007-03-12 19:19 ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Accessing an Associative Array
arr = new Array() myVar = elem2 arr[elem1] = hello arr[elem2] = hi trace(arr[myVar]) Jason Merrill Bank of America Global Technology Operations Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Abel Sent: Monday, March 12, 2007 3:42 PM To: Flashcoders mailing list Subject: [Flashcoders] Accessing an Associative Array How do you access an associate array using a variable? Inside my function popup[text]; won't access the array. I can't find any information in the books I have Actionsript Cookbook and Actionscript for Flash MX. Anyone dealt with this before? // Define the text and titles for the popups var myarray = { text: Lorem ipsum dolor sit amet ... }; // Testing - this works! trace(myarray[text]); // Show the popup function showPopup(popup) { mainMap[popup].gotoAndPlay(on); mainMap[popup].label_title.text = popup[text]; // This doesn't work. trace(popup[text]); }; showPopup(myarray); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Accessing an Associative Array
Variable identifiers are not string constants, so: showPopup(myarray); However mainMap[popup].gotoAndPlay(on); has no sense in this case, since the array notation excepts a string and not an object. Ans also you don't need to use array notation here at all, the simple dot syntax is enough: myarray.text and popup.text Attila BA How do you access an associate array using a variable? BA BA Inside my function popup[text]; won't access the array. I can't BA find any information in the books I have Actionsript Cookbook and BA Actionscript for Flash MX. BA BA Anyone dealt with this before? BA BA // Define the text and titles for the popups BA var myarray = { text: Lorem ipsum dolor sit amet ... }; BA BA // Testing - this works! BA trace(myarray[text]); BA BA // Show the popup BA function showPopup(popup) { BA mainMap[popup].gotoAndPlay(on); BA mainMap[popup].label_title.text = popup[text]; // This doesn't work. BA trace(popup[text]); BA }; BA BA showPopup(myarray); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Accessing an Associative Array
I think this is your problem: showPopup(myarray); You're passing showPopup a string with the value myarray, not the array. Remove the quotes and you should be good. -Andy On 3/12/07, Bill Abel [EMAIL PROTECTED] wrote: How do you access an associate array using a variable? Inside my function popup[text]; won't access the array. I can't find any information in the books I have Actionsript Cookbook and Actionscript for Flash MX. Anyone dealt with this before? // Define the text and titles for the popups var myarray = { text: Lorem ipsum dolor sit amet ... }; // Testing - this works! trace(myarray[text]); // Show the popup function showPopup(popup) { mainMap[popup].gotoAndPlay(on); mainMap[popup].label_title.text = popup[text]; // This doesn't work. trace(popup[text]); }; showPopup(myarray); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Accessing an Associative Array
How do you do it where myVar is the array? Is this possible? Or do you always have to specify the array? arr = new Array() arr[elem1] = hello arr[elem2] = hi function testArray(myVar) { trace(myVar[elem2]); }; testArray(arr); On Mar 12, 2007, at 3:17 PM, Merrill, Jason wrote: arr = new Array() myVar = elem2 arr[elem1] = hello arr[elem2] = hi trace(arr[myVar]) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Accessing an Associative Array
How do you do it where myVar is the array? Is this possible? Or do you always have to specify the array? Easy, just keep using the array access operator to evaluate: myVar = myArray2 myArray1 = new Array() myArray1[elem1] = hello myArray1[elem2] = hi myArray2 = new Array() myArray2[elem1] = wassup myArray2[elem2] = yo trace(this[myVar][elem1]) //traces wassup Jason Merrill Bank of America Global Technology Operations Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Abel Sent: Monday, March 12, 2007 5:02 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Accessing an Associative Array How do you do it where myVar is the array? Is this possible? Or do you always have to specify the array? arr = new Array() arr[elem1] = hello arr[elem2] = hi function testArray(myVar) { trace(myVar[elem2]); }; testArray(arr); On Mar 12, 2007, at 3:17 PM, Merrill, Jason wrote: arr = new Array() myVar = elem2 arr[elem1] = hello arr[elem2] = hi trace(arr[myVar]) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Accessing an Associative Array
Your right. I am passing a string. But I'm trying to use that string to access an array by the same name. someArray = { label: my text }; showPopup(someArray); // send a string which is the name of my array in the function: myDynamicText.text = myArray[label]; // try to use the passed string to access the array. This won't access some array. How do I convert that string over to something that will work? -b On Mar 12, 2007, at 3:46 PM, Andy Herrman wrote: I think this is your problem: showPopup(myarray); You're passing showPopup a string with the value myarray, not the array. Remove the quotes and you should be good. -Andy On 3/12/07, Bill Abel [EMAIL PROTECTED] wrote: How do you access an associate array using a variable? Inside my function popup[text]; won't access the array. I can't find any information in the books I have Actionsript Cookbook and Actionscript for Flash MX. Anyone dealt with this before? // Define the text and titles for the popups var myarray = { text: Lorem ipsum dolor sit amet ... }; // Testing - this works! trace(myarray[text]); // Show the popup function showPopup(popup) { mainMap[popup].gotoAndPlay(on); mainMap[popup].label_title.text = popup[text]; // This doesn't work. trace(popup[text]); }; showPopup(myarray); ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Accessing an Associative Array
Cool. That's it. Thanks so much! Needed to use the syntax; this[myStringVariableAndArrayName][myLabelInMyAssociativeArray]; My final code: // Show the popup function showPopup(popup) { trace(popup); mainMap[popup].gotoAndPlay(on); mainMap[popup].label_title.text = this[popup][labelText]; trace(this[popup][labelText]); }; On Mar 12, 2007, at 4:45 PM, Merrill, Jason wrote: How do you do it where myVar is the array? Is this possible? Or do you always have to specify the array? Easy, just keep using the array access operator to evaluate: myVar = myArray2 myArray1 = new Array() myArray1[elem1] = hello myArray1[elem2] = hi myArray2 = new Array() myArray2[elem1] = wassup myArray2[elem2] = yo trace(this[myVar][elem1]) //traces wassup Jason Merrill Bank of America Global Technology Operations Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Abel Sent: Monday, March 12, 2007 5:02 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Accessing an Associative Array How do you do it where myVar is the array? Is this possible? Or do you always have to specify the array? arr = new Array() arr[elem1] = hello arr[elem2] = hi function testArray(myVar) { trace(myVar[elem2]); }; testArray(arr); On Mar 12, 2007, at 3:17 PM, Merrill, Jason wrote: arr = new Array() myVar = elem2 arr[elem1] = hello arr[elem2] = hi trace(arr[myVar]) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com