Library items to the Stage
i have tomatoes in library named "tomato01" thru "tomato07". have array of names in it. have random function pics 1 of names @ time. want able place specific tomato on stage. ex if random number 7 put tomato07 on stage @ specific location , size.
do tomato items in library have ot have same class assigned it? not sure code.
can help?
this code have far 1 specific tomato. in advance.
code:
var tomatoarray:array = ["tomato01","tomato02","tomato03","tomato04","tomato05","tomato06","tomato07"];
var randomnumber:number = math.floor(math.random() * tomatoarray.length) + 0;
trace(randomnumber);
trace(tomatoarray[randomnumber]);
function main()
{
var newtomato:tomatosample = new tomatosample();
this.addchild(newtomato);
newtomato.x = 25;
newtomato.y = 45;
}
main();
if want able load 1 of tomatoes library, each need have unique class designation, such tomato01, tomato02, etc...
if want use string instantiate class instance, need use code such as...
var classref:class = class(getdefinitionbyname("classname"));
var classinstance:* = new classref();
addchild(classinstance);
where "classname" tomato01, tomato02, etc...
More discussions in ActionScript 3
adobe
Comments
Post a Comment