AS3 Tween on mouse event
Someone in another forum posted some code samples
demonstrating their use of tweens in AS3, which I had been having a
lot of trouble figuring out. The way it worked originally was a
little different -- 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. I confess I wasn't
completely sure of what I was doing, but it basically works.
The only problem is that I would like the circle and
textfield to tween only when clicked on. I don't know how to do
this. I figure it boils down to writing
_circle.addEventListener(MouseEvent.MOUSE_DOWN,....) and
_text.addEventListener(MouseEvent.MOUSE_DOWN, tweenerIt) in such a
way that they are the triggers, but it's beyond me.
It must be very simple, but I don't get it. Could someone
please explain? 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.
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;
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
You can do show/hide movieclip on mouseover. get your box
position and assign to the popup (tooltip movieclip).
see this...
not tested. but it should work.
import flash.events.MouseEvent;
function showClip(evt:MouseEvent) {
tooltips.x = evt.target.x + evt.target.width;;
tooltips.y = evt.target.y - evt.target.height;
tooltips.visible = true
function hideClip(evt:MouseEvent) {
tooltips.visible = false;
box.addEventListener(MouseEvent.MOUSE_OVER, showClip);
box.addEventListener(MouseEvent.MOUSE_OUT, hideClip);
I assume you'll create two movieclips named: box and tooltips
Similar Messages
-
Hi,
I had uploaded jpeg file onto the stage using
File->Import.
Now, how to access the mouse-events using AS3.0?
i.e., when we click with mouse on the stage
it should display the x and y co-ordinates of the point
being clicked.
These x and y coordinates must be displayed in text-boxes
provided down on the same stage.
Please reply meYou can do show/hide movieclip on mouseover. get your box
position and assign to the popup (tooltip movieclip).
see this...
not tested. but it should work.
import flash.events.MouseEvent;
function showClip(evt:MouseEvent) {
tooltips.x = evt.target.x + evt.target.width;;
tooltips.y = evt.target.y - evt.target.height;
tooltips.visible = true
function hideClip(evt:MouseEvent) {
tooltips.visible = false;
box.addEventListener(MouseEvent.MOUSE_OVER, showClip);
box.addEventListener(MouseEvent.MOUSE_OUT, hideClip);
I assume you'll create two movieclips named: box and tooltips -
Converting AS3 to AS2, mouse event
Does anyone know how to convert this code to AS2, I need it to work with my AS2 component:
button_instance.addEventListener(MouseEvent.CLICK,loadNewXML)
button_instance2.addEventListener(MouseEvent.CLICK,loadNewXML)
function loadNewXML(e:MouseEvent):void{
switch(e.target)
case button_instance:
myGallery.contentXML = "content.xml";
break;
case button_instance2:
myGallery.contentXML = "yourNewXmlLocation2.xml";
break;
The error that I'm getting is The class or interface 'MouseEvent'could not be loaded (line 4)
and '{' expected (line 6)kglad wrote:
try:
button_instance.onRelease = loadNewXML;
button_instance2.onRelease = loadNewXML;
function loadNewXML():Void{
switch(this._name){
case "button_instance":
myGallery.contentXML = "content.xml";
break;
case "button_instance2":
myGallery.contentXML = "yourNewXmlLocation2.xml";
break; -
Passing Param to Mouse Event in AS3
Hello All,
I want to make a tooltip box , when I mouse over an object it will appear with the object color and some other data
how can I send the color param and other param to mouse event?
Thanks in AdvanceHi,
Maybe this will help you :-
http://www.ultrashock.com/forums/actionscript/as3-adding-parameter-to-eventlistener-104729 .html
http://www.orlandmedia.com/blog/actionscript-3/passing-parameters-to-a-mouseevent-listener / -
Hello everyone,
I'm currently working on an standard as3 (1024x768) app that
is running inside a chromeless Air window to take advantage of the
transparency.
All my tests where done using windows XP professional and AIR
1.0 (the same problem existed in beta3).
The issue I'm having is related with Mouse Events. Somehow
the events take a lot of time to reach the swf file when the user
clicks inside the transparent window.
It's natural that the app runs slower inside a transparent
window (the framerate drops) but I wasn't expecting the clicks to
suffer from such delay (it takes sometimes 2-5sec).
The app is very CPU intensive and the transparencies make it
worse. Something inside the AIR framework is not dispatching the
events properly.
I say this because I tried using the virtualMouse class from
senocular together with a socket to simulate the mouse clicks and
that did the trick.
In conclusion:
Something in the AIR framework for windows XP is messing up
the dispatch of the Mouse events when the app is under heavy cpu
usage inside a chromeless window. I click on the window and it
takes 1-2sec to receive the click event.
However when I dispatch the MouseEvent.CLICK myself using
the virtual mouse class the application immediately receives the
event.
I know this is a strange bug and not many people will have
this problem, but I would like to know from someone with knowledge
of the runtime why this could be happening.
Thank you
Tiago BilouHello everyone,
I'm currently working on an standard as3 (1024x768) app that
is running inside a chromeless Air window to take advantage of the
transparency.
All my tests where done using windows XP professional and AIR
1.0 (the same problem existed in beta3).
The issue I'm having is related with Mouse Events. Somehow
the events take a lot of time to reach the swf file when the user
clicks inside the transparent window.
It's natural that the app runs slower inside a transparent
window (the framerate drops) but I wasn't expecting the clicks to
suffer from such delay (it takes sometimes 2-5sec).
The app is very CPU intensive and the transparencies make it
worse. Something inside the AIR framework is not dispatching the
events properly.
I say this because I tried using the virtualMouse class from
senocular together with a socket to simulate the mouse clicks and
that did the trick.
In conclusion:
Something in the AIR framework for windows XP is messing up
the dispatch of the Mouse events when the app is under heavy cpu
usage inside a chromeless window. I click on the window and it
takes 1-2sec to receive the click event.
However when I dispatch the MouseEvent.CLICK myself using
the virtual mouse class the application immediately receives the
event.
I know this is a strange bug and not many people will have
this problem, but I would like to know from someone with knowledge
of the runtime why this could be happening.
Thank you
Tiago Bilou -
Mouse events don't work on a button from a panel ran in a DLL
Hi.
I have a DLL that loads a panel.
Since it's a DLL I can't do the RunUserInterface() function, because the DLL would be stuck waiting for the panel events.
I only do the LoadPanel().
When I click with the mouse on one of the buttons, the pushing down event (simulating the button being pressed) doesn't happen and the callback doesn't run.
But if I press the tab button until the focus reaches the button and press Enter, the callback of the button is executed.
An even more interesting aspect is that this happens when I call the DLL on TestStand, but on an application of mine that calls the DLL just for debug everything works fine.
How can I enable the mouse events?
Thanks for your help.
Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
Solved!
Go to Solution.Hello Daniel,
I got surprised when I read your post, because I am experiencing something almost the same as you do.
I have a DLL (generated by an .fp instrument driver I wrote) which performs continious TCP communication with the UUT.
It starts 2 threads, each for reading from one of the 2 different IPs the UUT has.
Another DLL tests this UUT (with the help of the communication DLL above) by exporting functions to be called by TestStand steps.
If the second DLL wants to display a CVI panel in order to wait for the user response or displays a popup (MessagePopup, ConfirmPopup, etc), user cannot press the buttons.
Actually, there is a point your program and mine differ. I call RunUserInterface and the button's callbacks call QuitUserInterface, so the execution continues after a button is pressed. The problem is buttons cannot be pressed. I also tried looping on GetUserEvent but it did not solve the problem.
There are 2 findings:
1. I had a small exe to test my instrument driver DLL and the popups in it worked pretty well (this coincides with Daniel's findings).
2. We workedaround the problem by shutting down the communication threads in the instrument driver DLL before the popup appears and restrating them afterwards. Although they are separate threads in another DLL, they were somehow blocking user events on another DLL running.
S. Eren BALCI
www.aselsan.com.tr -
Firefox mouse event not behaving the same on PC and Mac computers
I use the FCKEditor and having a very strange problem. When I click on the FCKEditor's editing area, the keyboard gets disabled untill I click the mouse somewhere outside of the editing window. The problem only happen on Firefox (3.6.10) on Mac computer (Snowleopard 10.6.4). Doing exactly the same steps on PC works without any problem.
What I want to know:
- Is it possible that the Firefox on Mac is different than the PC in handling mouse events? Or some other areas?Sounds more that Firefox is treating that editor area as read-only.
Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]] -
Non modal PopUpManager blocking mouse events
In our application we have a header, footer and center area. We have a situation where we want to block the header and center area with a popup, but leave the footer area so it can be clicked on. The code works fine and it all looks good, except the mouse events are blocked to the footer. If we slightly resize the window (either with the mouse or programatically) it all "wakes up" and starts working. I have tried all sorts of invalidateDisplayList, validateDisplayList, validateNow, etc. I am throwing this out there to see if anyone else has had this problem and if there is something I am missing. I can't easily share my code, but if I don't get a reply I'll put together a code example to see if I can recreate it. Any ideas are very welcome. Been scratching my head at this one for 3 days now.
I should point out that we are using "false" for the modal flag, just in case anyone was thinking that. It all works fine once it "wakes up" through resizing, but I need to make that happen without the resizing.
And we have tried all sorts of "callLater" behavior in conjuction with the invalidate/validate calls. -
Mouse events during Thread.sleep
hi.
I have an applet .
I have a alghoritm simulator.
Everytime I find a solution I call the method Thread.sleep .
I want to pause the application and I create a JToggleButton Pause .
When I press the Pause during sleep mouse event are managed at the end of alghoritm.
How can I manage mouse events during sleep?All UI events (such as mouse events) occur on the event dispatch thread (EDT).
That means if you sleep on the EDT, you lock up the UI. For this reason, you shouldn't be sleeping on the EDT.
I'm not sure what your sleep is trying to do but you need to manage your threads a little more carefully. For instance, any time consuming process which is invoked as a result of a UI event needs to be fired on a new thread to prevent the UI freezing. The fun starts when you have to update the UI as a result of that process, because you should then hook back onto the EDT to avoid the risk of deadlock.
Some utility classes are provided, such as SwingUtilities, and other example code is provided on Sun's site, such as SwingWorker - but if you do much UI work you'll probably end up with your own core set of threading tools and so on to make life easier. -
HTML/JS: Capturing mouse events while Air is out of focus
Hi,
I've been trying to determine if it is possible to receive mouse events (like MOUSE_WHEEL) if the Air window does not currently have focus. I'd like my application to support the mouse wheel for scrolling while the cursor is over the application, without requiring the user to click the application and gain focus. My application uses JavaScript to scroll an unordered list within a DIV set to overflow:hidden (to prevent the native scrollbar from appearing).
Thanks for your help!
AndrewI doubt that AIR would pick up events fired while not having focus. Perhaps you could fake it by creating an AIR project that runs "fullscreen", but has a smaller active window. Anywhere your mouse went it would still capture the scrolling event, but you could conditionalize it so that it only worked in certain areas.
-
Mouse Events at the icon in systray.
My program call library function to add, modify or delete icon into systray.
Additionaly I'd like to get back information when any mouse event had happen under icon in systray like move mouse, right/left button click etc. to display popup menu (as an standart behaviour).
I've tried Windows Message Queue, but it only works inside application window area.
How could I do it ?
Any suggestions, examples or advises ?
Rumcajs.Requirements Price: $29.95
Application Software:
LabVIEW 7.0+
Toolkits Software:
Additional Software:
Language's:
LabVIEW
INVtray LabVIEW Toolkit allows the programmer to create a LabVIEW program that can be hidden from the task bar and accessed through the System Tray. Comes with a sample VI that demonstrates all the features of the toolkit. -
hi,
I am having objects on a JFrame that respond to mouse events. I would like to know how I can disable these events. I use the addMouseListener to register a mouse event on something. Is there a way to remove or to deregister mouse events.
I basically have a game of tiles on a JFrame and I am going to have the human player play against the computer. I want to be able to have turns; computer and human player turn.removeMouseListener()
-
Touch to Mouse events conversion
Hi Everybody!
Does anybody know how correctly fire mouse events to Oracle Maps in javascript?
Default translation touch events in iPad Safari does not quite fit. It try zoom or pan browser window, not map. :(
If catch touch events and disable default translation I can zoom and pan MVMapView object.
But how fire "click","mousemove","mouseover" events on Map? I need dispatch event to ThemeBasedFOIs (InfoWindow Popup and other listeners)?Yes. The Oracle Maps tutorial contains examples (the tutorial can be found in your mapviewer deployment
e.g. http://localhost:7001/mapviewer/fsmc/tutorial/index.html) and documentation in the API reference
(e.g. http://localhost:7001/mapviewer/fsmc/apidoc/index.html). Look at MVEvent and the attachEventListener function of MVMapView, MVThemeBasedFOI, and MVFOI classes for example. -
How to catch the mouse event from the JTable cell of the DefaultCellEditor
Hi, my problem is:
I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
Any idea will be highly appreciated!
Thanks in advance!Hi, bbritta,
Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
Thanks.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test3
extends JFrame {
// JTextField jtf = new JTextField();
Object[] as = {"aa","bb","cc","dd"};
JComboBox box = new JComboBox(as);
public Test3() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
String[] head = {
"One", "Two", "Three"};
String[][] data = {
"R1-C1", "R1-C2", "R1-C3"}
"R2-C1", "R2-C2", "R2-C3"}
JTable jt = new JTable(data, head);
box.addMouseListener(new MouseAdapter() {
// jtf.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e)
System.out.println("-------------------JComboBox mouseclick....");
jt.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e)
System.out.println("-------------------JTable mouseclick....");
// jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
content.add(new JScrollPane(jt), BorderLayout.CENTER);
setSize(300, 300);
public static void main(String[] args) {
new Test3().setVisible(true);
} -
Mouse event not fires on drag and drop
Please
Can any one help and give any idea during draging(drag drop) mouse over of a button does not fires. I have a list of thumb in which I want to drag and drop the thumb at any location for reordering the thumb but due to lot of item in list need to sscroll list. I have my own custom scroll on button mouse over but when Item is dragging mouse event does not fires.
Thanks in advance,
PremkantHi there,
Reject caption shows up when an unacceptable source is dropped on a Target. To configure the 'Accept criteria', select a drop target, Click on the 'Accept' button, Deselect the checkbox corresponding to the unacceptable source. (As shown below)
Now whenever the user drops 'Unaccept' source on top of the target, the 'Reject' caption shows up.
Thanks,
Nimmy Sukumaran.
Maybe you are looking for
-
This is the only site that Firefox has not asked me to save user name and password.
-
Can't import songs into itunes playlist folders from itunes music folder
Ive got to be an idiot. ive had my ipod for years and ive yet to figure this out: how do i put music into my playlist folders? The only playlists ive been able to successfully create and use are the ones ON my ipod. but that requires me to plug in my
-
Memory leak in weblogic server 5.1 sp 9?
We have been getting an out of memory error at production sites after several days of running. We changed the starup file to include the verbose:gc parameter and we are running jdk1.3.1_02. Over time the full garbage collection message shows that the
-
How can I obtain OS X and OS 9.2.2 Install CD's for second hand iMac??
Hello All you Mac users! I have always wanted a Mac and recently purchased a used iMac from Ebay for a good price, lovely condition beautifull machine. It came with OS X 10.2.8 loaded and fully functioning but with NO CD's or DVD for the OS. Having u
-
I click on the icon and firefox will not start or try to start
I installed Avery labels and then had trouble with tool bar remover avery but now firefox will not start up when i click on icon. I removed Firefox and reinstalled but will not run. == This happened == Every time Firefox opened == 5/19/2010 == == Use