Remove default event listeners
I am trying to use JComponent(JList, JTable) with a different behavior on mouse events. JTable for example selects the cells while dragging. I want to remove all curent listeners, I found removelistener, but I dont find getlisteners (removelistener requires the removed listener ).
getListeners
EventListener[] getListeners(Class�listenerType)
Return an array of all the listeners that were added to this JComponent with addXXXListener(), where XXX is the name of the listenerType argument. For example, to get all of the MouseListeners for the given Component c, one would write:
MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class))
If no such listener list exists, then an empty array is returned.
Similar Messages
-
If you have multiple event listeners running, is there any way to remove all of them at once rather than one at a time?
Thanks,
JeffNear the end of the article linked below is one approach that someone has used involving an array:
http://www.almogdesign.net/blog/actionscript-3-event-listeners-tips-tricks/ -
How to remove complex event listeners
circDraw.addEventListener(Event.ENTER_FRAME,function(e:Event){expand(e.target); },false,0,true);
function expand(obj):void {
obj.height+=3;
obj.width+=3;
How would I add a line here to remove that event?The more I look at that code the more I wonder about it. First I questioned why the function was not called directly in the event listener like it normally would be (since it appears to be utilizing the event.target), then I wondered why an ENTER_FRAME event is being cancelled as soon as it seemingly starts. Is circDraw the obj of the function? If so, why it isn't all that just reduced to being...
circDraw.height+=3;
circDraw.width+=3;
with no listeners or functions involved.
Maybe you have an explanation that I can't see from what is shown. -
How can I remove default alarm for events in iCal on devices ios?
Whenever I add an event to my iCal calendar in Mounain Lion it will automatically add one default alert only on my iphone and ipad. These default alarms are not displayed on my macbook or icloud.com
Default alarms are disabled in macbook, icloud.com, and my ios devices.
How can I remove default alarm for events in iCal on devices ios?
Thanks and sorry for my english.
MacBook Pro, Mac OS X 10.8OK, so I have had this issue for the past several months. I think it all started when I upgraded to ML from SL and migrated my calendars and contacts to iCloud. That was a couple months ago. But now I am running 10.8.2, and about two weeks ago I upgraded my iOS devices to 6.0.1.
I don't seem to be having any issues with events that I create now, but all those old events that were migrated to iCloud a couple months ago, many of those sound alerts on the iOS devices even though there was no alert defined when the event was originally created. I have always had alerts off by default both in iCal and on the iOS devices.
So here's the question: is there a way to go through and disable all these spurious event alerts? I've been disabling them as the event reminders come up, but it's irritating. It would be nice if there was a way to turn them off all in one shot somehow. -
Removing Event Listeners - Are they needed all the time
My goal is to increase the performance of my project so I would like to know if it is always a good idea to remove event listeners. More specifically, lets say I have a movie with severals scenes and several frames within those scenes. Each one of the frames has an event listener:
Example:
Scene 1
Frame 1 (EventListener)
Frame 2 (EventListener)
Frame 3 (EventListener)
Frame 4 (EventListener)
Scene 2
Frame 1 (EventListener)
Frame 2 (EventListener)
Frame 3 (EventListener)
Frame 4 (EventListener)
Questions:
Does Flash continue to listen for an event in Scene 1/Frame 1 when the playhead has moved to Scene 1/ Frame 2?
Or does Flash just listen for the events when the playhead is in a particular frame only?
Should I remove the event listener once I leave a particular frame (should there be remove event listeners on each frame)?Just mentioning, the addEventListener comes with a parameter you can set to true or false called a weak reference. On desktop flash apps it can become time consuming to constantly remove listeners, especially when things drop off the display list frame to frame. You can mark them for automatic garbage collection by using the weak reference property.
e.g.
Credits_bnt.addEventListener(MouseEvent.CLICK, goCredits, false, 0, true); // set weak reference to true (e.g. remove when no references exist anymore automatically)
Eventually garbage collection will remove that reference automatically when there's nothing left on the display list or in memory to use it.
However, if this is targeted at mobile, you absolutely want to remove the reference as soon as possible when it's not needed for memory conservation. On a desktop it's not that big of a deal. -
Does removeChild remove the object's event listeners?
Hi
If you dynamically create a parent movieclip, and dynamically add a color picker to each clip, and add an event listener for each color picker, does a removeChild on the parent movieClip remove event listeners belonging to any of it's children?
Thanks
ShaunAhh - thanks Ned
Is there any software you could recommend that monitors and shows you what or how many event listeners are open, memory consumption etc, to help you to trim the fat from your coding?
Thanks
Shaun -
Remove Event Listeners (at the right time)
I have a app which loads multiple flv's, I also have a timer
(digial) which shows how long the movie has been played for. The
problem is that whenever i load and new move (through the same
"loadVideos()" function, the timer variables ("lagTime", "endTime")
are not reset (even though the correct variables are being passed.
I believe it has something to do with the event listeners which are
being used to load the movies. How can i clear all the listerner
before reloading the movies?
Here is a code snippet:
Thanks in advanceThanks, kglad
Yes it traces 'endTime' but what happens is that when i play
the first movie is will display for example ("40,40,40,40" etc...)
until the video stops playing. If i load another movie it will then
trace ("40, 20, 40, 20, 40" etc...) so i need to kill the
listereners and reload the variables.
Jake -
Hello!
I have a PopUpManager window that fires an event just before closing (not the CloseEvent).
I am listening for that event and handling it in a function.
Q: Is it best practice to remove the listener in the function that handles it or calling PopUpManager.removePopUp on that popup automatically does the "cleaning" as well?
Thank you!Removing the eventListeners on a popup window is necessary I believe.
In your event handling function, you can remove the event listener by event.target.removeEventListener(..., ...). It doesn't matter that your component is handle by the popUpManager, you'll still have a reference to it.
Example
In main app:
var win:myClass = PopUpManager.createPopUp(this, myClass, true) as myClass;
win.addEventListener("myEvent", myHandler);
private function myHandler(evt:Event):void
evt.target.removeEventListener("myEvent", myHandler);
In custom myClass:
private function handleSomething(evt:Event):void
var ev:Event = new Event("myEvent");
dispatchEvent(ev);
if (isPopUp)
PopUpManager.removePopUp(this as IFlexDisplayObject);
Does this help?
Dany -
Using Multiple Event Listeners
Hi,
I have a movielcip (A) class in which I have used a Tween class effect on a child movieclip (B) scrollRect. The (B) Movieclip in turn has several movieclips whose have tween class effect being executed on thier child movieclips.
the tweens are all unique to each movieclip
and the event listeners are taken off once completed.
This works all well and good in FLASH IDE...
My problem arises when I try to view this in a browser on a Windows XP
it doesnt work in
Opera Version 9.63
Firefox 2.0
and Google Chrome 2.0
The only browser it works fluently in is
Internet Explorer 7.0.5
What is happening in most cases it that the animation appears to "stick" but i think what may be happening is the listening or removal of the event listeners. The animations are left incompleted.
Is there any rule of thumb when using multiple event listeners?
here is a snippet of some of my code
on click event from movieclip (A)
private function scrollToSlidePrev(e:MouseEvent) {
if (((slideIndex - 1) >= 0)) {
nextButton.mouseEnabled = nextButton.enabled = previousButton.enabled = previousButton.mouseEnabled = false;
var position:Number = 0-SLIDEAREA.width;
var slide1:TileListSlide = slides[slideIndex] as TileListSlide;
var slide2:TileListSlide = slides[--slideIndex] as TileListSlide;
scrollSlide(position,slide1,slide2);
tween animation in movieclip (A) on (B)
private function scrollSlide(pos:int,slide1:TileListSlide,slide2:TileListSlide) {
slide1.resizeSlideTo(0.6); // execute tween on child movie clips in B
slide2.resizeSlideTo(1); // same as above;
var rect:Rectangle = sliderMc.scrollRect;
var tween1:Tween = new Tween(rect,"x",Regular.easeOut,rect.x,rect.x + pos,3,true);
tween1.addEventListener(TweenEvent.MOTION_CHANGE,setSliderScroll,false,4);
tween1.addEventListener(TweenEvent.MOTION_FINISH,toggleButtonEnabled,false,3);
tween animation in movieclip (B) children
public function resizeSlideTo(sc) {
var m:Matrix = tileList.transform.matrix as Matrix;
var p:Point = new Point (m.a, 0);
var tween2:Tween = new Tween(p,"x",Regular.easeOut,p.x,sc,3,true);
if (numericStepper != null) {
if (sc != 1) {
numericStepper.visible = false;
tween2.removeEventListener(TweenEvent.MOTION_FINISH,showStepper);
if (sc === 1) {
tween2.addEventListener(TweenEvent.MOTION_FINISH,showStepper,false,2);
tween2.addEventListener(TweenEvent.MOTION_CHANGE,setScaleOnScroll,false,3);
here is the link
http://visual_admin.web.aplus.net/ticker/ticker_widget.html
the effect disables and re-enables the buttons when its done.... then the listeners are removed.
each one with the exception cretes its own unique tween (obviously this is a custom class built as each clip)
i really don't know what to make of it guysapparantly making the tween a property of the class rather than a random variable in a function worked.....go figure
-
Clearing default event handlings
I am trying to use JComponent(JList, JTable) with a different behavior on mouse events. JTable for example selects the cells while dragging. I want to remove all curent listeners, I found removelistener, but I dont find getlisteners (removelistener requires the removed listener ).
Using getListeners you can by
MouseMotionListener[] mls = (MouseMotionListener[])(ImTab.getListeners(MouseMotionListener.class));
for (int i=0;i<mls.length;i++) {
ImTab.removeMouseMotionListener(mls);
Then you write your own method .
Thanks for noah :-) -
Loading/Unloading a .swf that adds event listeners to the Stage
Hi all,
Disclaimer
Apologies if I suck so bad at using forum search that the answer to this is on page 1 somewhere; I tried...
Question
I am loading and unloading a .swf to which I do not have source code access. This .swf places several event listeners on the stage, as far as I can tell. When the .swf is unloaded, the event listeners placed upon the stage still seem to be in effect. Using unloadAndStop doesn't seem to do it, and I have to target Flash Player 9, anyway, so can't really use it. Is there any other way I can keep this external .swf from holding onto my main movie's stage?
Additional info
All eventListeners and references being set by my code are removed.
I've managed a little contact with the author of the .swf:
I've requested he provide a dispose() method I can call to get all the listeners removed, and send an updated .swf.
He's suggested that I should be able to avoid the problem by loading into a unique ApplicationDomain. I'm not terribly familiar with this, but have given it a try without much success. Is this a valid solution - can I really protect my 'stage' by properly using ApplicationDomains - or do I need to persist in trying to get a public dispose() method built in?
Thanks in advance!
Cheers, Johnthanks for reply sir
sir actually, i have not any problem with loading any file but i need to go back to intro.swf file when i click on clsbtn of main.swf, i want unload the main.swf file and panel.swf file
actually i did was, i have intro.swf file and there is button by clicking load main.swf file (where is timeline controling butons) and in the main file automatically load panel.swf file ( where is all animation)
its all play gud , no problem
but my problem is there is a clsbtn in main.swf file and when i click on that button everything should be unload and it should return on the previous position in intro.swf
i hope u understand what i am trying to say -
Managing various event listeners in multi-frame movie
I'm working on a gunslinger game. I have numerous frames
which correspond to different stages of the game. The frame that
corresponds to the actual gameplay has a really involved
ENTER_FRAME function attached to particular item on the stage. When
the game is over (or an error occurs, or the network connection
fails) I want to leave the gameplay frame and move to some other
frame. When this happens, I would like the ENTER_FRAME function on
the gunslinger to be removed because the player may finish a game
and then re-enter the gameplay frame later after selecting a new
opponent.
QUESTION: Can anyone recommend a good way to manage the
keyboard event listeners, all the button event listeners, etc? As
you might imagine, I have no reliable way to determine which frame
might be entered after the gameplay frame because the frame change
could be triggered by a variety of different reasons.I have tried using hasEventListener to check for an existing
ENTER_FRAME function before adding the event listener again but it
never seems to notice that there is an existing enterframe function
running. Furthermore, when I leave the frame, the enterframe
function (which is attached to a particular movie clip on frame 2)
continues to run even though that movie clip doesn't exist on any
other frame in the flash movie.
The first frame in my movie just has a button that takes the
movie to frame 2. frame 2 has a movie clip (myMovie) and a button
(btnFrame1) which goes back to frame 1. It also has the attached
actionscript.
I start the movie.
I click 'goto frame 2'
the enterframe listener is added and starts to output trace
statements of the current frame of myMovie (e.g., 1-2-3).
i click 'goto frame 1' on the main movie
although i am looking at frame 1 of my main movie which has
no instance of myMovie, the enterframe function keeps tracing the
current frame--interestingly, the frame of myMovie does not
advance...it stays on 1, 2, or 3 and announces that frame over and
over again.
Repeating the visit to frame 1 and frame2 over and over again
results in more listeners being added over and over again.
I have uploaded a sample FLA here:
http://jaith.net/questions/listenerExample.zip
I hope that you might help me determine how to remove the
listener upon exiting this frame. I don't want that enterframe
function running (and referring to movieclips that don't exist)
when I exit the frame where it is relevant. I'm wondering if I
should try adding the event listener to the root movie
instead. -
Is there a way to clear ALL event listeners, stop all movie clips, etc?
Is there a syntax for this?
I have a movie that has 15 frames. Each frame has embedded movie clips within movie clips, tons of animations and event listeners. None is needed except when they are on the stage, on the frame. However, the animations continue even when the frame is left.
For instance, I have a frame that has a dynamically rendered animation of leaves falling from a tree. When the frame is left, the leaves continue to fall.
There are many instances of this type of thing happening.
Ideally, I would love to just be able to clear everything when a new frame is loaded, since none of the animations or event listeners need to carry over from one frame to another.
Is there a way to do this without the thousands of lines of code it would take to manually remove every single animation and event listener and sound, etc, from the stage?
Thanks so much!!
Amberyou have to manually do that.
or, you could convert each frame to a swf. load each swf when needed and, if you're publishing for fp 10+, you can apply unloadAndStop() to kill all streams in the loaded swf and ready those assets for gc. -
To display consecutive words from an array on a keypress. Event listeners not working.
I need to display a series of words consecutively on a black background. A new word presented each time the Enter key is pressed (It is necessary that its the same key each time i.e the Enter Key). The words are arranged in an array. I have created a function for each Keypress and a listener. Also, as the previous word is replaced by the next, I have a removeChild() to get rid of the the last word.
I have a removeEventListener set up also, to avoid any problems with the listeners. I have been at this a long time without sucess. It must be a listener problem (i.e I have not got the listeners focussed properly?) or a display problem. It only ever displays one word. Please see below code for the display of two of the words from the array which is called cvcwords. The main problem is that the words do not display one after the other (indeed not at all, except for the first one) when the enter key is pressed. Very much as a powerpoint presentation would, thats the idea anyway. I have just a sample of the code below. any help appreciated.
var cvcwords : Array = ["bad", "mod", "hud", "mit", "sat", "fog", "puc",];
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
function modKeyDown(e : KeyboardEvent) : void {
if (e.keyCode == Keyboard.ENTER) {
removeChild(myText); // to remove previous word from screen
myText.text = cvcwords[1]; //to display element one of the array
addChild(myText);
} else if (e.keyCode == Keyboard.SPACE) { //this is for another seperate option
myText.text = "try again";
addChild(myText);
this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, hudKeyDown);
function hudKeyDown(e : KeyboardEvent) : void {
if (e.keyCode == Keyboard.ENTER) {
removeChild(myText); //to remove previous word from the screen
myText.text = cvcwords[2];
addChild(myText);
} else if (e.keyCode == Keyboard.SPACE) {
myText.text = "do again";
addChild(myText);
this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, hudKeyDown);Based on what I see of your code, the following is all you might need...
var cvcwords : Array = ["bad", "mod", "hud", "mit", "sat", "fog", "puc",];
var counter:int = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
function modKeyDown(e : KeyboardEvent) : void {
if (e.keyCode == Keyboard.ENTER) {
myText.text = cvcwords[counter];
counter++;
} else if (e.keyCode == Keyboard.SPACE) {
myText.text = "try again";
addChild(myText);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
When you test this in Flash, in the player you need to be sure to select the Diable Keyboard Shortcuts option found under the Control option in the top toolbar
If you really mean to have them try again, you probably do not want to remove the event listener -
Memory cost of unremoved event listeners
Anyone have any insight into the memory usage of
eventlisteners in AS3, and whether allowing them to build up within
an application causes performance issues? Why isnt there a global
method that removes all listeners (or maybe there is?).
ThanksThank you kglad. It seems I stumbled upon an interesting
discovery today, and was wondering if you can confirm.
It appears that AS allows you to have duplicate
eventlisteners on objects. In other words, if you add 5 duplicate
listeners to an oject (e.g mc.addEventListener(MouseEvent.CLICK,
someFunction) x 5), then try to remove the event listener
(mc.removeEventListener(MouseEvent.CLICK, someFunction)), it is
only removing one of the event listeners right?
If that is the case, then can I do something like this to
remove them all? while (mc.hasEventListener(MouseEvent.CLICK)){
mc.removeEventListener(MouseEvent.CLICK, someFunction);
Thanks
Maybe you are looking for
-
Hello, I have a UC560 and UC540 connected using an IPSec Site to Site tunnel. There is a server on the main site they are trying to access (lets say IP is 192.168.1.252) and they need to access this server on ports 13000, 14000, and 15000. Unfortunat
-
TS3297 Music download failure (failed to be downloaded but has been paid)
I tried to purchase a song from iTunes but it failed giving a notice saying that the billing address does not match the card info or whatever. There was nothing wrong with the card info so I changed the billing address and try to confirm the purchase
-
Building OutlineFields dynamically
Hi all, I need to build dynamically an OutlineField : Example : I have an Array of a class which contains an Array of TextData which I convert in an array of a class named "LineClass" inheriting of the DisplayNode class. What I want to do is to build
-
Youtube not working with 3Gs, its only working with Wifi
Hello, Can anyone help, i can only seem to get youtube on my new 3Gs iphone through wifi. Every time i try to connect through 3Gs it does not connect and displays the text "load more" with no pictures. Thank you.
-
Merging/Flattening Layers with different blending modes and maintaining the visual appearance
Hello, I see there are many others that are having the same problem as me. And alas, it doesn't seem like the problem has been solved or very understood for that matter. I want to be able to take a document, that has multiple layers, inside of multip