Solved

Flex Mobile: Create an array that holds ID and name for each user

Posted on 2013-05-10
2
429 Views
Last Modified: 2013-05-11
Hello

I want to create an array(Object) that holds ID and Name of an user, after that then also how to do the for each user and grab the current Name and ID in the 'for each' statement.

How can this be done, both the population of the array and also the manegement of the 'for each' statement for it.

Data sample:
Username:ID
hest:12873127389
john:71283723
Niel:2311232312
0
Comment
Question by:JoachimPetersen
2 Comments
 
LVL 19

Accepted Solution

by:
Gary Benade earned 500 total points
ID: 39155692
var users:Array = new Array();

// technique 1
var user:Object = new Object();
user.Username = 'hest';
user.ID = 12873127389;
users.push( user );

// technique 2
users.push( { Username:'john', ID:71283723 } );
users.push( { Username:'Niel', ID:2311232312 } );

for each( var user:Object in users)
{
	trace( 'Username:' + user.Username + " ID:" + user.ID);
}

Open in new window

0
 
LVL 29

Expert Comment

by:dgofman
ID: 39155870
Or you can use similar to hashmap

var users:Object = new Object();
users[12873127389] = "hest";
users[71283723] = "john";
users[2311232312] = "Niel";

for (var id:String in users)
       trace( 'Username:' + users[id]+ " ID:" + id);

The advantages using HashMap you can grad user name by id

var lookupId = 2311232312;
trace( 'Username:' + users[lookupId]);
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now