Jump to content
Search Community

how to add tweening and change the sprite to the moveclip?

waley test
Moderator Tag

Recommended Posts

1how to add some twenning in this code? :roll:

2 then I want to change the sprite to the moveclip,how to do it?

thank you for helping me.

 

the code:

 

 

package{

import flash.display.Sprite;

import flash.events.MouseEvent;

 

public class MouseEvents extends Sprite{

public function MouseEvents(){

init();

}

private function init():void

{

var sprite:Sprite=new Sprite();

addChild(sprite);

sprite.graphics.beginFill(0xff0000);

sprite.graphics.drawCircle(0,0,50);

sprite.graphics.endFill();

sprite.x=stage.stageWidth/2;

sprite.y=stage.stageHeight/2;

 

sprite.addEventListener(MouseEvent.CLICK,onMouseEvent);

sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onMouseEvent);

sprite.addEventListener(MouseEvent.MOUSE_DOWN,onMouseEvent);

sprite.addEventListener(MouseEvent.MOUSE_UP,onMouseEvent);

sprite.addEventListener(MouseEvent.MOUSE_OVER,onMouseEvent);

sprite.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseEvent);

sprite.addEventListener(MouseEvent.ROLL_OUT,onMouseEvent);

sprite.addEventListener(MouseEvent.ROLL_OVER,onMouseEvent);

}

public function onMouseEvent(event:MouseEvent):void

{

trace (event.type);

}

}

}

Link to comment
Share on other sites

first import the greensock classes

 

import com.greensock.*;

import com.greensock.easing.*;

 

then

public function onMouseEvent(event:MouseEvent):void
{
trace (event.type);

TweenLite.to(sprite, 1, {x:200});

}

 

 

keep in mind every mouse event that you registered wlll cause the sprite to tween, so you should add a switch statement or temporarily remove a bunch of those listeners.

 

you can tween a Sprite or any displayObject, it doesn't have to be a MovieClip.

 

I don't really understand the meaning or intention behind your second question. perhaps you can explain more.

 

please read the docs and view the interactive demos on http://www.greensock.com/tweenlite as they explain in detail the code I provided.

 

best,

 

Carl

Link to comment
Share on other sites

2 then I want to change the sprite to the moveclip,how to do it?

thank you for helping me.

 

package{
import flash.display.Sprite;
import flash.events.MouseEvent;

public class MouseEvents extends Sprite{
public function MouseEvents(){
init();
}
private function init():void
{
var sprite:Sprite=new Sprite();
addChild(sprite);
sprite.graphics.beginFill(0xff0000);
sprite.graphics.drawCircle(0,0,50);
sprite.graphics.endFill();
sprite.x=stage.stageWidth/2;
sprite.y=stage.stageHeight/2;

sprite.addEventListener(MouseEvent.CLICK,onMouseEvent);
sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_DOWN,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_UP,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_OVER,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseEvent);
sprite.addEventListener(MouseEvent.ROLL_OUT,onMouseEvent);
sprite.addEventListener(MouseEvent.ROLL_OVER,onMouseEvent);
}
public function onMouseEvent(event:MouseEvent):void
{
trace (event.type);
}
}
}

 

You might also have to import display.MovieClip to get the functionality you are asking for... or you could possibly cast the sprite as a movieclip when you need to use it like that.

MovieClip(sprite)

or

sprite as MovieClip

If you do everything the same way but with MovieClip in the place of Sprite it should work fine... I might not be understanding the question as there could be some details being lost in translation

Link to comment
Share on other sites

2 then I want to change the sprite to the moveclip,how to do it?

thank you for helping me.

 

package{
import flash.display.Sprite;
import flash.events.MouseEvent;

public class MouseEvents extends Sprite{
public function MouseEvents(){
init();
}
private function init():void
{
var sprite:Sprite=new Sprite();
addChild(sprite);
sprite.graphics.beginFill(0xff0000);
sprite.graphics.drawCircle(0,0,50);
sprite.graphics.endFill();
sprite.x=stage.stageWidth/2;
sprite.y=stage.stageHeight/2;

sprite.addEventListener(MouseEvent.CLICK,onMouseEvent);
sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_DOWN,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_UP,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_OVER,onMouseEvent);
sprite.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseEvent);
sprite.addEventListener(MouseEvent.ROLL_OUT,onMouseEvent);
sprite.addEventListener(MouseEvent.ROLL_OVER,onMouseEvent);
}
public function onMouseEvent(event:MouseEvent):void
{
trace (event.type);
}
}
}

 

You might also have to import display.MovieClip to get the functionality you are asking for... or you could possibly cast the sprite as a movieclip when you need to use it like that.

MovieClip(sprite)

or

sprite as MovieClip

If you do everything the same way but with MovieClip in the place of Sprite it should work fine... I might not be understanding the question as there could be some details being lost in translation

 

 

I change the word "sprite" to "MovieClip",also add a movieclip named sprite,but there is nothing happened.

Link to comment
Share on other sites

i think the problem is also that you are declaring your

 

var sprite:Sprite=new Sprite();

 

inside the init() function.

 

that means that sprite is only accessible inside that function.

 

the function onMouseEvent is not aware of what sprite is.

 

----

 

try moving var sprite:Sprite=new Sprite();

outside of any methods

Link to comment
Share on other sites

thank for helping ,I have done it.

the fact,I mean I use sprite, It is OK.but when it is a movieclip,i need to do this.

first I draw a ball named sprite or another name, I change it as a movieclip.

second I chose the ball ,Linkage properties,Export for ActionScript ,fill the class:sprite;the base class:flash.display.MoveClip.

third I change my code ,I use "aba" take the place of "sprite",and use "Sprite" take the place of "MovieClip",then RUN it.It can be worked.

 

although I have done it,but I know that object can be everything, why I need to do that ,or I fail?

My English is poor,sorry!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...