Welcome, Guest. Please login or register.
Did you miss your activation email?
02/09/12, 03:02
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash 8 (Moderators: Jorge Solis, ..:: Mazhar Hasan ::.., Andresss)
| | |-+  create tween with actionscript
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: create tween with actionscript  (Read 1393 times)
skitzer
Jr. Programmer
**
Posts: 84


View Profile
« on: 11/06/06, 12:36 »


Can someone please tell me how I can create a motion tween using actionscript?  I want a ball moving around in a circle (so oriented to a path).  I know about the Tween class, but I'm not sure how to do this using it. 
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #1 on: 11/07/06, 12:07 »

Ok, assuming your ball have an instance name of "ball", use:

angle 0
centerX 
270
centerY 
200
radius 
100
speed 
.1
this
.onEnterFrame = function(){
	
ball._x centerX Math.cos(angle) * radius
	
ball._y centerY Math.sin(angle) * radius
	
angle += speed
}

Jorge
Logged

winxalex
Server what's that
*
Posts: 26


View Profile
« Reply #2 on: 11/13/06, 04:06 »

Using onEnterFrame is the oldest and still much relabile method but u can got in mass pretty soon .
 Next method is using setInterval which is more OO,  like this:
 
angle = 0
centerX = 270
centerY = 200
radius = 100
speed = 10


function Move(){
   ball._x = centerX + Math.cos(angle) * radius
   ball._y = centerY + Math.sin(angle) * radius
   angle += 1
}


   setInterval(Move,speed);


Cos of extended need of tweenin( move,rotate, change color or...) MM has made Tween class
(imortant!!!  Move ur "ball" rotation center as u like ur radius to be)
speed=500;

import mx.transitions.Tween;
var myTween:Tween = new Tween(ball, "_rotation", mx.transitions.easing.None.easeNone,0,360, speed, false);
myTween.onMotionFinished = function() {
    trace("finished")
   myTween.start();
};

    myTween.start();
Logged
skitzer
Jr. Programmer
**
Posts: 84


View Profile
« Reply #3 on: 11/15/06, 14:36 »

Thanks to both of you. 

Can you help me figure out how to do this using an oval?  I have an oval on the screen and I want the ball to move along it.........
« Last Edit: 11/15/06, 14:41 by skitzer » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #4 on: 11/15/06, 15:07 »

Use different radius for _x and _y

Jorge
Logged

skitzer
Jr. Programmer
**
Posts: 84


View Profile
« Reply #5 on: 11/17/06, 14:54 »

Merci Jorge.
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!