actionscript 3 - I want to move a random object -
actionscript 3 - I want to move a random object -
i have square , want when press button, position square move randomly in programme ..
when press button nil happens.
what wrong code?
var mycolor :colortransform = new colortransform(); mycolor.color = math.floor(math.random() * 0xffffff) var xposition:number = math.random() * (150 - 50) + 50; var yposition:number = math.random() * (150 - 50) + 50; trace(yposition); var rectangle:shape = new shape; // initializing variable named rectangle rectangle.graphics.beginfill(0x0000ff); rectangle.graphics.drawrect(0,0, 100, 100); // (x spacing, y spacing, width, height rectangle.graphics.endfill(); rectangle.transform.colortransform = mycolor; addchild(rectangle); addeventlistener(mouseevent.click, generaterandom) function generaterandom(event:mouseevent):void { rectangle.graphics.moveto(100, 70); btn.label = "asd"; }
the function moveto not used determine position
, move current drawing position
.
you have write:
btn.addeventlistener(mouseevent.click, generaterandom); function generaterandom(event:mouseevent):void { rectangle.x = math.random() * (150 - 50) + 50; rectangle.y = math.random() * (150 - 50) + 50; }
actionscript-3
Comments
Post a Comment