# Is dictionary the best way to ID a class property in an event function?

**URL:** https://forum.kirupa.com/t/is-dictionary-the-best-way-to-id-a-class-property-in-an-event-function/293125
**Category:** flash
**Created:** [July 23, 2009, 3:04pm UTC](https://forum.kirupa.com/t/is-dictionary-the-best-way-to-id-a-class-property-in-an-event-function/293125 "2009-07-23T15:04:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kerpob](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kerpob](https://forum.kirupa.com/u/kerpob)
#### Post date: [July 23, 2009, 3:04pm UTC](https://forum.kirupa.com/t/is-dictionary-the-best-way-to-id-a-class-property-in-an-event-function/293125/1 "2009-07-23T15:04:55Z")

</div>

[FONT=Times New Roman][SIZE=3]I have a question about accessing properties of a custom class from within another class. I can do it, but I’m not sure if I am doing it the right way – or if there is a simpler alternative.[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]I have a class called “legion” it contains a couple of properties, a sprite called “legio” and an integer called “loc”[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]I import the legion class into another class called “Main”.[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]Within Main I have a loop to create many versions of legion, passing parameters so that they all have unique loc values. These are put into an array called “legarray”:[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]**for (i:int=0; i\<20; i++) {**[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]**legarray.push(legion(i\*10));** [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] **}** [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]I use the same loop to _addChild(legarray.legio)_\*[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]I also add an event listener so that you can click and drag the sprites around.[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]This means that there is a single event function called within Main for whatever legio sprite is clicked.[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]As you can’t pass variables to an event function, I can move the sprite with:[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] **currentTarget.x = whateverx** [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]but I cannot change the loc variable[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]currentTarget.loc or target.loc don’t work…[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]I solved the dilemma with a dictionary object storing the name against i in the loop, so that I can do:[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3][/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]**legarray[dictionaryobj(currentTarget)].loc = whatevern**[/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]So, is there another way?[/SIZE][/FONT]

(using flex sdk & SciTE)
