How to access data in an Array?

I need to move my targets in the “onBubblaKlick”-function to the x and y positions defined in the bubblaData-Array [COLOR=“Red”](marked in red)[/COLOR]. But I can’t figure out how to access them? Any solutions out there?


var bubblaArray:Array = [];
var bubblaData:Array = [[56, 432, .5, "picknick", "Text", [COLOR="Red"]1[/COLOR], [COLOR="Red"]34[/COLOR]],
				[ 182, 408, .6, "restaurang", "Text", 70, 789], 
                                [ 322, 245, .7, "vindkraft", "Text", 63, 300],
				[ 334, 427, .8, "varutransport", "Text", 70, 150],
				[ 522, 636, .9, "dagvatten", "Text", 70, 542],
				[ 605, 489, 1, "cyklist", "Text", 20, 300],
				[ 735, 185, 1.1, "lagenhet", "Text", 70, 150],	
				[ 880, 159, 1.2, "solceller", "Text", 70, 150],
				[ 935, 422, 1.3, "kollektivtrafik", "Text", 200, 300]];

// Animera in bubblorna
for (var i:Number = 0; i < 9; i++) 
{
	var a:Bubbla = new Bubbla();
	var placeBubbla:Object = { _scale:1, time:2, transition:"easeoutelastic", delay:bubblaData*[2] }
	var bubblaX = bubblaData*[0];		// x-position
	var bubblaY = bubblaData*[1];		// y-position
	var bubblaName = bubblaData*[3];	// vilket scenario
	var infoText = bubblaData*[4];	// scenario-rubrik 
	[COLOR="Red"]var moveX = bubblaData*[5];[/COLOR]
	[COLOR="Red"]var moveY = bubblaData*[6];[/COLOR]
	
	a.scaleX = a.scaleY = 0;
	a.filters = [shadow];
	a.x = bubblaX;
	a.y = bubblaY;
	a.name = bubblaName;
	a.bubblaText_txt.text = infoText;
	a.bubblaText_txt.alpha = 0;
	
	Tweener.addTween( a, placeBubbla );
	addChildAt ( a, 1 );
	bubblaArray.push(a);
	
	a.addEventListener( MouseEvent.CLICK, onBubblaKlick );
	a.addEventListener( MouseEvent.ROLL_OVER, bubblaStor );
	a.addEventListener( MouseEvent.ROLL_OUT, bubblaLiten );
}

// Klick på bubblorna
function onBubblaKlick( evt:Event ):void {
	var target = evt.currentTarget;
	
	Tweener.addTween( target, { _scale:2.5, x:[COLOR="Red"]moveX[/COLOR], y:[COLOR="Red"]moveY[/COLOR], time:1, transition:"easeoutlinear" } );
	
	for ( var p in bubblaArray ) {
		if ( bubblaArray[p] != target ) {
			Tweener.addTween( bubblaArray[p], fadeBubbla );
		}
	}
	
	target.removeEventListener( MouseEvent.CLICK, onBubblaKlick );
	target.removeEventListener( MouseEvent.ROLL_OVER, bubblaStor );
	target.removeEventListener( MouseEvent.ROLL_OUT, bubblaLiten );
	
	var myRequest:URLRequest = new URLRequest ( "scenario/"+target.name+".swf" );
	myLoader.load ( myRequest );
}

what you have there looks like this… no?!

[AS]var acessAr:Array = [[‘a’, ‘b’, 3],[‘c’, ‘d’, 5]];

for (var i:uint = 0; i < acessAr.length; i++)
trace(acessAr*[2]);[/AS]

but this works fine for me…
what error gives you?

I tried it like this but it always move my target to the last data in my Array. I doesn’t seem to cycle thru it and pick the targets data… what I’m I doing wrong?


for (var j:uint = 0; j < bubblaData.length; j++)
		Tweener.addTween( target, { _scale:2.5, x:bubblaData[j][5], y:bubblaData[j][6], time:1, transition:"easeoutlinear" } );

bennymartensson, did you try to trace the values? what does it give you?

No need anymore, I figured it out. This is how I did it, got the index number of the target and used this to find my way in the Array. Thanks for you time in this matter! :slight_smile:


function onBubblaKlick( evt:Event ):void {
	var target = evt.currentTarget;
	var targetNum:Number = bubblaArray.indexOf(target);
	var moveX:Number = bubblaData[targetNum][5];
	var moveY:Number = bubblaData[targetNum][6];
	
	Tweener.addTween( target, { _scale:2.5, x:moveX, y:moveY, time:1, transition:"easeoutlinear" } );
}

hey… really I was not understanding what was your problem. Sorry for the blindness… I just thought that you where having trouble getting the value inside the for cycle… and I couldn’t find any problem there… hummm know I get it and so do you :stuck_out_tongue: