Hey all, title may be abit misleading but i didnt know the correct way to write it.
Basically, how can i do the AS3 equivalent of this php code:
return array('x' => 0, 'y' => 0);
The standard way of doing it is like this. The main thing to remember is that 'Object' in AS3 is almost equivalent to PHP's associative array's.
var obj:Object = {x:0, y:0};
trace(obj['x']); // like in PHP
trace(obj.x); // also valid
// AS3 version of foreach in PHP
for(var key:String in obj) {
trace(key +" = " + obj[key]);
}
private var map:Dictionary = new Dictionary();
map["x"] = 0;
map["y"] = 0;
{x:0,y:0}, can only use the syntax as shown above)You can do something like this
var myArray:Array = new Array({x:'0'},{y:'1'},{x:'2'});
or
var myArray:Array = new Array({x:'0',y:'1'},{a:'1',b:'2'});
myArray[0]['x'], myArray[1]['y'], and so on, instead of just myArray['x'] or myArray['y']. Most people don't do it this way and just use a plain Object.