AS3 - Tween On Mouse Event
Someone in another forum posted some code demonstrating tweens in AS3, which I had been having a lot of trouble figuring out. All it does is tween the x and y positions of a circle and textfield. The way it worked originally was a little different--for instance, I've tinkered a bit by putting the tween functions in a separate Tweener class and made it so it accepts whatever display object is passed to it. The problem is that I would like the circle and textfield to tween only when clicked on. I don't know how to do this. How do I write _circle.addEventListener(MouseEvent.MOUSE_DOWN,....) and _text.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt) so that they are the triggers? Just so you will have an idea of what I'm talking about I've set it up so that the tweens occur as soon as the circle and textfield are created. It must be very simple, but I just don't get it. Could someone please explain?Code: package{ import mx.effects.*; import flash.display.*; import flash.events.*; import mx.effects.easing.*; import flash.text.TextField; import com.Tweener; public class TweenTest extends Sprite { private var _circle:Sprite; private var _text:TextField; function TweenTest() { stage.frameRate = 31; init(); } private function init():void { _circle = makeCircle(); _text = makeTextField(); var myTween:Tweener = new Tweener(_text, 40, 300, 150, 100, 4000); var myTween2:Tweener = new Tweener(_circle, 0, 60, 300, 200, 8000); // not sure what to put here... //_circle.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt); //_text.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt); } private function tweenerIt():void {// not sure what to put here.. } private function makeCircle():Sprite { var s:Sprite = new Sprite(); s.graphics.beginFill(0x660000); s.graphics.drawCircle(20, 20, 20); addChild(s); return s; } private function makeTextField():TextField { var t:TextField = new TextField(); t = new TextField(); t.text = "Hello"; t.x = 20; t.y = 60; addChild(t); return t; } }}Code: package com{ import mx.effects.*; import flash.display.*; import flash.events.*; import mx.effects.easing.*; public class Tweener extends Sprite { private var _target:DisplayObject; private var _target_dest_x:Number; private var _target_dest_y:Number; private var _target_start_x:Number; private var _target_start_y:Number; private var _duration:Number; public function Tweener(target:DisplayObject, target_start_x:Number, target_start_y:Number, target_dest_x:Number, target_dest_y:Number, duration:Number) { _target = target; _target_dest_x = target_dest_x; _target_dest_y = target_dest_y; _target_start_x = target_start_x; _target_start_y = target_start_y; _duration = duration; tweenMe(); } private function updateTween(vals:Array):void { _target.x = vals[0]; _target.y = vals[1]; } private function endTween(vals:Array):void { trace ("ending coordinates: " + vals); } private function tweenMe(/*e:Event*/):void { var myTween:Tween = new Tween(_target, [_target_start_x, _target_start_y], [_target_dest_x, _target_dest_y], _duration, 31); myTween.easingFunction = Elastic.easeOut; myTween.setTweenHandlers(updateTween, endTween); } }}Fingers
Actionscript 2.0
Posted on: Tue Nov 21, 2006 4:49 am
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
AS3 - Tween On Mouse Event
If the code looks familiar to anyone, some of it is excerpted from a post by devonair. All it does is tween the x and y positions of a circle and textfield. I've tinkered with it a bit by putting the tween functions in a separate Tweener class and made it accept whatever display object is passed to it. For demonstration purposes, I have it set up so that the tweens occur as soon as the circle and textfield are created. The problem is that I would like the tweens to occur only when they are clicked on. I don't know how tp do this. How do I write _circle.addEventListener(MouseEvent.MOUSE_DOWN,... .) and _text.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt) so that they are the triggers?
It must be very simple, but I just don't get it. Could someone please explain?
Code:
package
{
import mx.effects.*;
import flash.display.*;
import flash.events.*;
import mx.effects.easing.*;
import flash.text.TextField;
import com.Tweener;
public class TweenTest extends Sprite {
private var _circle:Sprite;
private var _text:TextField;
function TweenTest() {
stage.frameRate = 31;
init();
}
private function init():void {
_circle = makeCircle();
_text = makeTextField();
var myTween:Tweener = new Tweener(_text, 40, 300, 150, 100, 4000);
var myTween2:Tweener = new Tweener(_circle, 0, 60, 300, 200, 8000);
// don't know what to put here...
//_circle.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt);
//_text.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt);
}
private function tweenerIt():void {
// don't know what to put here
}
private function makeCircle():Sprite {
var s:Sprite = new Sprite();
s.graphics.beginFill(0x660000);
s.graphics.drawCircle(20, 20, 20);
addChild(s);
return s;
}
private function makeTextField():TextField {
var t:TextField = new TextField();
t = new TextField();
t.text = "Hello";
t.x = 20;
t.y = 60;
addChild(t);
return t;
}
}
}
Code:
package com
{
import mx.effects.*;
import flash.display.*;
import flash.events.*;
import mx.effects.easing.*;
public class Tweener extends Sprite {
private var _target:DisplayObject;
private var _target_dest_x:Number;
private var _target_dest_y:Number;
private var _target_start_x:Number;
private var _target_start_y:Number;
private var _duration:Number;
public function Tweener(target:DisplayObject, target_start_x:Number, target_start_y:Number, target_dest_x:Number, target_dest_y:Number, duration:Number) {
_target = target;
_target_dest_x = target_dest_x;
_target_dest_y = target_dest_y;
_target_start_x = target_start_x;
_target_start_y = target_start_y;
_duration = duration;
tweenMe();
}
private function updateTween(vals:Array):void {
_target.x = vals[0];
_target.y = vals[1];
}
private function endTween(vals:Array):void {
trace ("ending coordinates: " + vals);
}
private function tweenMe(/*e:Event*/):void {
var myTween:Tween = new Tween(_target, [_target_start_x, _target_start_y], [_target_dest_x, _target_dest_y], _duration, 31);
myTween.easingFunction = Elastic.easeOut;
myTween.setTweenHandlers(updateTween, endTween);
}
}
}
Fingers
Event Listener Mouse Event Click - Obstructions
This is an oversimplification of my problem.
I have an event listener on a sprite.
I then have portions of this sprite covered with other sprites or moveclips.
If I click a movieclip, it blocks my eventlistener on the sprite underneath it.
Is it possible to listen to the even click 'through' a movieclip. I dont want interaction with them, but I dont want them as bitmap data onto the base sprite either...
Mouse Event, Event.target Vs Movieclip Name
Hi -
Can anyone help me with a mouse event issue, i'm truly baffled. There's a timer event that loads 4 movieclips (named 'serviceType'), each containing an instance of 2 objects (named 'btn' and 'thumbs'). When clicking on the MC (servicetype) it triggers a mouse event. I'm trying to reference child 'thumbs' of the serviceType MC but in the mouse event function, event.target traces no children, but serviceType traces the 2 children. BUT serviceType only refers to the last instance of serviceType that was loaded in the timer event. Why wouldn't event.target work??
Here's the code, and thanks for the help!!
ActionScript Code:
function loadServices(event:TimerEvent):void {
count = event.target.currentCount -1;
serviceType = new MovieClip;
addChild(serviceType);
btn = new Btn(serviceList, count);
thumbs = new ThumbContainer(count);
serviceType.addChild(btn);
serviceType.addChild(thumbs);
serviceType.addEventListener(MouseEvent.CLICK,loadThumbs);
}
function loadThumbs (event:MouseEvent):void {
trace(serviceType.numChildren); /// Displays 2 (but refers to the last instance loaded)
trace(event.target.numChildren);// Displays 0, why??
}
Mouse Event Add Event Listener?
sorry, could not think of a better title!
anyway,
I downloaded a class that perfectly works for me,
it's basically a cube that rotates depending on mouse movement,
the way it does it is with the following line:
spBoard.addEventListener(MouseEvent.MOUSE_MOVE,boa rdMove);
what this does is, whenever the mouse moves the cube moves
the boardMove function does the movement based on the mouse's current position
but what i want to do is the keep the cube moving, if the mouse is on its left, it keeps rotating left, and on its rght, keep rotating right...and preferably to have the speed increase/decrease depending on how far/close mouse is to the center of the cube
any suggestions?
firstly is there an event listener that keeps calling the function just for the mouse 'being there' ? i tried rollover, didn't work
or maybe the boardMove function should be modified? i have no idea how though, totally new to AS3, here's the boardMove function for refrence:
ActionScript Code:
private function boardMove(e:MouseEvent):void {
var locX:Number=prevX;
if(doRotate){
prevX=spBoard.mouseX;
curTheta+=(prevX-locX);
renderView(curTheta);
e.updateAfterEvent();
}
}
Mouse Event Handler Vs. Mouse Listeners?
I found an example use of the onMouseDown, onMouseMove, and onMouseUp event listeners in the ActionScript help files. The example used a listener to listen for the mouse events and draw boxes when the user clicks and drags. I removed the listener and the SWF still seems to work just fine. (See the mouseEventTest.fla.) I don't understand why someone would want to use a mouse event listener if it's not necessary to detect onMouseDown, onMouseMove and onMouseUp. Can someone explain this?
Maybe I'm just not understanding the difference between the listeners used with the top-level Mouse class and the onMouseDown event handlers that work with movie clips. Does my mouseEventTest.fla work without the listener because it's treating the onMouseDown as though it's a movie clip event handler associated with _root?
Tween Event Problem
Hi all,
I have the following code:
Code:
function test():void
{
var tween:Tween = new Tween(popup_mc, "alpha", Strong.easeOut, 1, 0, .15, true);
tween.addEventListener(TweenEvent.MOTION_FINISH, popupInvisible);
}
Sometimes, the event listener for the tween does not initiate the popupInvisible() function - is there something I am doing incorrect or could this be improved?
Thanks in advance for any support
Mx.transitions.Tween Event Listener?
Hi,
I am using the mx.transitions.Tween class and need to know when tweening completes. Where can I find documentation for the event listeners that this class handles?
Thanks
Wierd Interuptions To A Tween Event
I have a tween and use continueTo() to move in clips. Everyonce and a while it will just freeze and not move. Is there any reason a continueTo would just stop even though it hasn't completed to where it was told to move to?
Tween Class And Event Handlers
I am finally trying to learn how to get off of the timeline now that I am out of school for awhile. I've read up on the crude basics of the tween class and I am trying to redo my site in all AS. Anyway here's my very lauhable first few lines of code.
ActionScript Code:
box1_mc._alpha=0
box2_mc._alpha=0
box2_mc._y=15
box2_mc._x=52
bar1_mc._alpha=0
Box1 = new mx.transitions.Tween(box1_mc, "_x", mx.transitions.easing.Regular.easeInOut, 0, 50, .5, true)
Box1 = new mx.transitions.Tween(box1_mc, "_alpha", mx.transitions.easing.Regular.easeInOut, 0, 100, .5, true)
Box1.onMotionFinished = function() {
Box2 = new mx.transitions.Tween(box2_mc, "_xscale", mx.transitions.easing.Regular.easeInOut, 0, 100, 1, true)
Box2 = new mx.transitions.Tween(box2_mc, "_alpha", mx.transitions.easing.Regular.easeInOut, 0, 100, .25, true)
}
Box2.onMotionFinished = function() {
Bar1 = new mx.transitions.Tween(bar1_mc, "_alpha", mx.transitions.easing.Regular.easeInOut, 0, 100, .25, true)
}
So far, I have 3 movie clips. And all I am trying to do is have one fade in/animate, then the next, then the next. The first two do, but the third one doesn't show up. Am I using the handler wrong or something? Any glaring errors?
On Mouse Event
This shold be simple. I want a Movie Clip to start over when you click it. I found the action script, but the OnMouseEvent is greyed out. Any ideas?
Russell
On Mouse Event
I would like to replace a movie clip with another one on a mouse event but I I can't get it to work.I have tried to call it with a tell target but it dosen't work.
Thanks
Shawn
On Mouse Event
I have created a button, and when I go to select "On Mouse Event", it is greyed out and not active.
How do you activate this action?
Mouse Event
Am doing a mouse over to load a movie..everything is fine..would like to have movie dissapear when mouse is off button, could someone please help....thanks
On Mouse Event
I am having problems with this event handler.
i have 2 movieclips. each one has an on mousedown event handler attached to it. each one has a different specific geturl action if a mousedown is detected. for some strange reason, once one movie clip is pressed, it triggers the geturl action in the other movie clip as well, opening both url's - the one clicked and the one not clicked.the evnt handler is not on the movieclip that contains both movie clips. any ideas? any other time iv'e done this it was as simple as it sounds - not this time....thanx
Mouse Event
I am new to flash and I have both version 5 and MX. I am trying to add an action to some text in my movie. What I want is when someone clicks on this test they are taken to another frame. I am trying to add this action but the 'mouse event' selection is greyed out. Can someone help me?
Thanks
Michael
On Mouse Event
i am trying to follow tutorial but it says to add the "on mouse event" action and i cannot find it in MX. Does MX not do that anymore?
Mouse Event
Right is it possible to insert an image where u click the mouse? so say i click on the centre of the screen the imported image will appear there?
tnx
bbb
Mouse Event
ok well i have this nav bar right... each link you roll over there is a little effect, the links cover the entire swf.
here lies the problem:
:::::::::::::::::::::::::::::::::::::::::::
on a layer below the links, there is a little movie clip
there are 2 frames 1 - 2 with stop on both...
what i want to do is this:
when the mouse is present on the swf it plays 2.
when the mouse is not on the swf it plays 1.
how can i accomplsh this?
:::::::::::::::::::::::::::::::::::::::::::::
any help is welcomed!
thanks guys
Mouse Event
How do u do a script similar to the media player function when you move the mouse a list appear with a play list ? in other word a mouser listener so when i move the mouse in flash the player appears any one got a link or script ?
//RaZorCleaN
[CS3] Help With Mouse Over Event Please :)
Hi
I'm making a menu that is made up of two rows of images,3 at the top and 3 at the bottom. I have got to the point where i have all images in place and an actionscript has been applied so that the images increase in scale when the mouse moves over them. The only problem is that when you move the mouse over some of the images, they increase in scale but are behind some of the images which have not been enlarged. Can someone please help me?
Kind Regards
Jerum
Mouse Over Event
hi, made a small moviclip of a line that moves.
how do i get it to move only on mouse over?
thank you
On Mouse Event
Hi , tornado here,
I am looking for some help with an onmouse event. I want my images to slide right when my mouse is over them to the right , and then move left when i move my mouse to the left. Can anyone please help me with this problem. I have seached for tutorials and if anybody knows of one , please let me know
cheers
tornado
Mouse Event Nothing
Hi there,
I think i have a very simple question:
Is there any way to let a movieclip do something when the mouse isnt over it.
for exaple:
on (nothing) {
gotoAndStop(1);
}
or is there any way to get this effect?
Greets,
Fregl K
On Mouse Event Greyed Out... Why?
Hi all!
I'm trying to make a skip intro button and I've used one of the default common library buttons (VCR Black) and I've placed a text symbol called "skip intro" over the top of it. But for some reason when I try and add the action command "On mouse event", it won't let me. It is greyed out as if I cannot select it. Can anyone tell me what could have caused this?
Thanks for your help pros!
-Airswift-
Mouse Rollout Event
What exactly does the mouse event (rollout) do?
I know what it is supposed to do (when moving mouse out of the button area with it on it should do something that you call when rollout occurs?) but I have never got it working!
Usually I make an invisible button that has a rollover and this acts as the rollout but I can't do it in this case as there is a button directly underneath which stops this from working.
Thanks!
Capturing Mouse Event?
hy,
is there any way for a button action to happen if the mouse pointer, while the button being depressed, mooves in and out of the hit area. (something like paintbrush).
drag out and drag over don't do the thing that I want cause the button action hapens if the mouse button is depressed while in the hit area.
thanx in advance.
On Mouse Event Dbl Click?
Hello
How can i made a buton that will activate on dbl click mouse event ??? Is that posible?
thanx
Right Mouse Click Event
How do I disable the right mouse click on my movie... or something similar to that? Maybe... concider the right click to be left click? I don't know.. I only know some action script, please help
On Mouse Event Troubles?
I am having a hard time accessing the on mouseevent action. Whenever i highlight my button and get up the actions palette, all the basic actions work and i am able to select them but the on mouseover action doesnt work at all? It wont let me select it for my buttons. I have gotten this to work before but cannot figure out how to get it to work again. I have tried several methods but with no success. What am i missing?
On (mouse Event) Not Working
hi.
i'm creating a drop down menu through flash 5 but whenever i try and put and action script: on (roll over) etc... i cant because it's not highlighted in the "basic" list and won't let me make the action. can anyone help me out
thanks.
PS. also, the onclipevent isn't highlighted aswell.
Xml - Flash, Mouse Event ?
hi,
we have dynamic text being pulled from an xml file.
(we have that much working)
the nodes are something like
name (or category)
person
url
what we want to do is if the text has a url value,
i would like it to mouse over a highlight (behind it).
i am guessing that it would be something
like if it has a url then load this symbol...
????
i have no idea what the action script would be or where it should go?
can someone help a first time poster??
thanks a bunch,
panda
Conditional On Mouse Event
I have a movie clip which is basically a "popup" in the middle of the screen, but when it comes up I want to disable all the buttons that are on the main timeline. Is there a way to achieve this?
I tried putting a conditional on a button outside of the movie clip, something like:
if (movie_clip_is_showing == false) {
on (rollOver) {...}
}
but I got scripting errors.
I would be interested in some kind of Flash 4 or Flash 5 solution.
Playing MC On Mouse Event
Hi everyone,
This is what I'm trying to do. I have a movie clip that is long horizontally. I have 2 buttons (left & right) that I want to use to scroll the movie clip with the mouse press and release events.
I have the following code so far:
on (press) {
do {
pics.nextFrame();
} while (pics._currentFrame <> 40);
}
on (release, releaseOutside) {
pics.stop();
}
now, this is not working properly because I'm guessing it does the loop too fast. I tried placing a for loop in the do while to kinda force a pause, but that didn't work.
Anyone have any ideas??
Thanks,
Tony
Mouse Event And Confusion
I have a 20x20 grid of circles all using the same movieclip. It basically duplicates one movie clip to build the grid when the flash movie is run.
I need these circles to change color when you hold the mouse down and drag over them. I want to simulate a paint brush to get the idea that you are painting the circles while the mouse is held down.
I am having trouble, it seems that I can get it to change color when you click or mouse over, but I can't get it to do both at the same time.
The only way I got this to work was to do a hit test with a movieclip attached to the pointer. Well this is 400 loops all executing at the same when the mouse down occurs, and slows the movie down significantly.
Any help would be grateful!!
Transitions Between Swf's On Mouse Event
Im trying to get good transitions between swf's on mouse clicks. What im doing now is I have a mc that is called transition that has the animation i want to use between movies when a button is clicked. Then i have an empty mc that i load transition and the swf's into called empty_mc . I have the action
onClipEvent (data) {
_root.transition._visible = 0;
}
----ON MY EMPTY MC----
--Then i have the action--
on(release){
_root.emptymc.loadMovie("contact.swf");
_root.transition._visible=1;
}
------On a button------
--Then i have the action--
onClipEvent(load){
this._visible=0;
}
------On my transition mc------
The problem with this is that the transition mc runs untill the swf is loaded so it eigther just repeats itself or doesnt play fully depending on how big the swf is. Im trying to figure out how i can get the mc to play through fully just once and then load the movie. If anyone can help i would appreciate it greatly ive been working on this for a long time. If you want to see the movie in question and what it does this is the link http://www22.brinkster.com/ruberbabi/starter.html
Mouse Event Transitions
I posted yesterday with no response. Im just trying to get some advice on a good way to transition between movies on mouse clicks. So like you click a button and it transitions between a movie instead of just unloading it and loading the next. Im trying to figure out a good way to smoothly do it. You can check out my post from yesterday to see what i have now or please any suggestions would be greatly appreciated.
OnLoad Or Mouse Event?
Let say I have the following script in a frame:
lv = new LoadVars();
lv = new LoadVars();
lv.sendAndLoad("update.php", receivelv, "POST" );
receivelv.onLoad = function(success) {
_root.update_status = this.update_status;
}
Flash would KEEP checking if the variable(s) is finished loaded or not. If it the variable is loaded completely. It would execute the onLoad function, right?
My problem is: if i put the above script inside a button, as you know, the button action is only triggered for mouse event. If the variables are not completely loaded right after the mouse event, will Flash still keep checking? if the variables are fully loaded 5 seconds after mouse event, will it still execute the onLoad function after 5 seconds of the mouse's trigger? or only another mouse event's trigger would cause the other checking?
Sorry for my poor english, hope can make you understand. Thanks
Mouse Over Event Problem
I looking to make my mouse stay as a pointer instead of a hand and i want it to go to another keyframe when entering object. Enclosed is my file. I would appreciate the help. Thanks
Mouse Event Problem
i am trying to make this site in flash 5. everything is working fine just that i cant get the mouse event working properly. all i want is when the user clicks on a text, it plays an animation. for this, i used the on (release) event. but my problem is when i click on the button more than once, the box animates and this kinda looks not nice. i cant really explain it in words( sorry for my english ) but if you go to my web site and click on any of the buttons continuously, you would see what i meant!! its still under construction though!!
thanks for any support.
my web site is:
http://www33.brinkster.com/rocrulzs/
Using Keypress Mouse Event
I've got a flash presentation that continuously plays (loops)
I would like the flash to stop playing and open a browser window when someone hits the spacebar. When they hit the spacebar again I would like the flash to resume playing.
How is this done?
Loading A Swf On Mouse Event
hi ,
can anyone pleeeease help me.
i am a beginner.i m actually a designer. and totally new to scripting in flash mx. my problem is i have a button and on relesing it i need to play a .swf.file. the script i wrote is
on relese(){
gotoAndplay("home.swf");
}
but its not working.
i have put the swf in the same folder as the fla file. i donno hw to do the scripting.
pleese help me . anyone who sees this. i did b really grateful.
its real urgent.
thanking u.
timmy
Loading A Swf On Mouse Event
hai everyone,
i found sm mistakes in my script.
and corrected it as
on (release) {
gotoAndplay("home.swf");
}
but still not working.
please help me. pleeese. its going to cost my new job.
lov
timmy
Mouse And Keypress Event
Dear Gurus,
I want to be able to run script on a button when I press the space bar, and it needs to happen to the button that the mouse is over. I have the following script:
on(rollOver){
if (Key.isDown(Key.SPACE)) {...
}
}
and it works fine if I rollover the button whilst holding the Space bar, but it does not work if the mouse is already over the button and I press the Space Bar which is what I need.
Thanks in advance.
[MX] Flash Mouse Over Event Help
Hi Guys,
Can anyone help me on this? Pleeeeeeeeeeeeeeeeze !!
I just wanted to create a flash piece similar to the one like this http://www.pg.com ( can you see a flash piece in the middle ).
To make it easy to understand: here is the functionality it has... there are 4 animations for 4 links which are playing simultaneously. Now, when I am taking my mouse to the other links, its playing the animation corresponding to that particular link and the same for all 4 animations and links. Also clicking on the links taking me to a different url.
See the sliding mouse over effect. Looks very simple but tough to make. :P
Can you help me on this please
|