PDA

View Full Version : Sprite appearing in wrong position for 1 frame



sargeonline
January 10th, 2008, 06:40 PM
Hey I'm just going through the Friends of Ed book, Actionscript 3.0 Animation and just noticed in some of their examples that the ball sprite is appearing the wrong spot, at position 0,0 on the stage for a second, probably 1 frame. I'm just wondering if there was a way to make it go to the position specified straight away, instead of after 1 frame or so.

Here's a sample 2 classes of what I'm using.

Ball Class:


package {

import flash.display.Sprite;

public class Ball extends Sprite {

private var radius:Number;
private var color:uint;

public function Ball(radius:Number=40,color:uint=0xff0000) {
this.radius=radius;
this.color=color;
init();
}

public function init():void {
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}

}
}Circle Class:


package {

import flash.display.Sprite;
import flash.events.Event;

public class Circle extends Sprite {

private var ball:Ball;
private var angle:Number=0;
private var centerX:Number=200;
private var centerY:Number=200;
private var radius:Number=50;
private var speed:Number=.1;

public function Circle() {
init();
}

private function init():void {
ball = new Ball();
addChild(ball);
ball.x=0;
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}

public function onEnterFrame(event:Event):void {
ball.x=centerX+Math.sin(angle)*radius;
ball.y=centerY+Math.cos(angle)*radius;
angle+=speed;
}

}
}Thanks in advance!

Felixz
January 10th, 2008, 07:26 PM
instead ball.x=0;
use onEnterFrame(null)

sargeonline
January 10th, 2008, 07:55 PM
Excellent, worked a treat. It seems to work even if I leave the ball.x=0 there. Would it cause any problem if you left ball.x=0 in any situation? Or doesn't it really matter.

Cheers for the quick reply!

Felixz
January 11th, 2008, 03:02 PM
if u left it program does useless operation