actionscript 3 - trace of array not changing after item's value was change -
so got 2d array simple map editor.
every tile/cell of map have value of 0 default , mouseclick event listener.
(var i:int =0; < _numrow; i++) { _map[i] = new array ; (var j:int = 0; j< _numcol; j++) { //i removed content _tile.val = 0; _tile.addeventlistener(mouseevent.click,onmouseclick); addchild(_tile); _map[i][j] = _tile.val; } }
edit: click tile/cell, happen. problem commented.
private function onmouseclick(e:mouseevent) { if (e.currenttarget.val == 0) { e.currenttarget.val = 1; trace(e.currenttarget.val); // trace output want, 1 of each tile clicked. e.currenttarget.transform.colortransform = new colortransform(1,0,0); trace(_map[0]); // check here if _map change since _map[x][x] = _tile.val, should output change made above. [[1,1,1,0,1,0...]] }
but no output wasn't change. _map still = [[0,0,0,0,0,0,0...]]
said maybe i'm missing simple thing here don't know what. if still wasn't clear please tell, explain more. guys.
--scratching original answer--
what want achieve can done in 2 ways:
- store _tile in _map[i][j]
- or, store {"num": 0} in _tile.val , assign _map[i][j] _tile.val. then, while fetching value _map, use _map[i][j].num , update value in _tile _tile.val.num = 1.
the problem facing can pictorially shown as:
_map[i][j]---| | |----| |->| 0 | _tile.val----| |----|
but, after assign 1 _tile.val, result like:
_map[i][j]-->|-----| | 0 | |-----| _tile.val--->|-----| | 1 | |-----|
hope helps.
Comments
Post a Comment