My Questions are:
1- I want to link a text to an image, both text and images are in an array. So, when I get the photo randomly from the array, I need to display the text.
2- I want to display the text with the image in the stage, but how to put text in a specific place in stage.
Hope to get feedback soon guys.
Code: Photos = new Array();
photo2 = new img2();
photo3 = new img3();
photo4 = new img4();
//put those images into an array
Photos.push(photo2);
Photos.push(photo3);
Photos.push(photo4);
//photo1.personDetails;
//photo1.imageName;
compass1.addEventListener(MouseEvent.CLICK, addPhoto);
//http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/arrays.html
var elements:Array = [];
elements[ 0 ] = [ "A", "B", "C" ];
elements[ 1 ] = [ "D", "E", "F" ];
elements[ 3 ] = [ "G", "H", "I" ];
trace( elements[ 0 ][ 0 ] ); //A
}
// Pick random Element of an Array Actionscript 3
function getRandomElementOf(Photos:Array):Object {
var idx:int=Math.floor(Math.random() * Photos.length);
trace(idx);
return Photos[idx];
}
public function addPhoto(e:MouseEvent) {
trace("clicked compass");
stage.addChild(DisplayObject(getRandomElementOf(Photos)));
}
multidimensional arrays. At one dimension you keep images and other the text vice versa. Here is a help page about the arrays. link