Skip to main content
Participating Frequently
May 13, 2008
Question

Random Moving Words

  • May 13, 2008
  • 4 replies
  • 718 views
Hello All!

I'm about 2 hours into ActionScript 3 ... and to flash.. haha! I'm trying to have words move/appear randomly in different locations and I found some code online for something that is very similar to what I want but it is in AS2. Can someone please help me translate. I've started attempting a translation but I think a pro would do it better. If you need the translation I've got so far I can post it later.

This is the AS2 code:
for(i=0;i<5;i++) {
var t = this.attachMovie("ball","ball"+i,i);
t._x = Math.random()*450;
t._y = Math.random()*400;
t.dx = Math.round(Math.random()*450);
t.dy = Math.round(Math.random()*400);
t._xscale = Math.random()*300+40;
t._yscale = t._xscale;
t.onEnterFrame = mover;
}

function mover() {
this._x += (this.dx-this._x)/2;
this._y += (this.dy-this._y)/2;
if(Math.round(this._x) == this.dx) {
this.dx = Math.round(Math.random()*450);
this.dy = Math.round(Math.random()*400);
}
}

This topic has been closed for replies.

4 replies

May 16, 2008
oh there is mistake in your code of AS3.0.. you are trying to set the propertices like.x or.y but way is wrong.. try to put the hardcode value... after sucess u can put random method
.

thanks
Participating Frequently
May 16, 2008
Yep the coding should be definitely raw.
Luis-NewbAuthor
Participating Frequently
May 15, 2008
Anyone?
Luis-NewbAuthor
Participating Frequently
May 15, 2008
So lot's of work and here is where I'm stuck:

for(var i:int=0;i<60;i++) {
var t = this.addChild(new word());
t.DisplayObject.x = Math.random()*450;
t.DisplayObject.y = Math.random()*400;
t.dx = Math.round(Math.random()*450);
t.dy = Math.round(Math.random()*400);
t.DisplayObject.scaleX = Math.random()*300+40;
t.DisplayObject.scaleY = t.DisplayObject.scaleX;
t.onEnterFrame = mover;
}
function mover(t:MovieClip) {
this.DisplayObject.x += (this.dx-this.DisplayObject.x)/3;
this.DisplayObject.y += (this.dy-this.DisplayObject.y)/3;
if(Math.round(this.DisplayObject.x) == this.dx) {
this.dx = Math.round(Math.random()*450);
this.dy = Math.round(Math.random()*400);
}
}

and I get the following error in the output:

TypeError: Error #1010: A term is undefined and has no properties.
at RandomInnovationWords_fla::MainTimeline/RandomInnovationWords_fla::frame1()
Luis-NewbAuthor
Participating Frequently
May 14, 2008
I think my usage of the this. function is incorrect for AS3 and also the whole this.attachmovie transition to MovieClip is all wrong
Ned Murphy
Legend
May 14, 2008
It'll be better if you post what you have translated so far so that unnecessary effort isn't expended for things you may have already done correctly.
Luis-NewbAuthor
Participating Frequently
May 14, 2008
Here it is.. I may be totally off. I've changed some of the migrated bits like t._x and also sought to change the this.attachmovie bit with stuff I've found in the forum. Hope it helps and don't be afraid to simply tear this apart

Thanks

for(var i:int=0;i<60;i++){
var word:MovieClip;
var t = word;
t.DisplayObject.x = Math.random()*450;
t.DisplayObject.y = Math.random()*400;
t.dx = Math.round(Math.random()*450);
t.dy = Math.round(Math.random()*400);
t.DisplayObject.scaleX = Math.random()*300+40;
t.DisplayObject.scaleY = t._xscale;
t.onEnterFrame = mover;
}
function mover() {
this.DisplayObject.x += (this.dx-this.DisplayObject.x)/3;
this.DisplayObject.y += (this.dy-this.DisplayObject.y)/3;
if(Math.round(this.DisplayObject.x) == this.dx) {
this.dx = Math.round(Math.random()*450);
this.dy = Math.round(Math.random()*400);
}
}