ActionScript 3.0 :: Remove Stage Event Listeners?

Feb 5, 2010

I create a stage keyboard event listener in an externally loaded swf such as:

Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);

My question is how and where I should remove this event listener? I have added an unload event handler to the external swf like this:

Code:
this.loaderInfo.addEventListener(Event.UNLOAD, unloadHandler);

The unloadHandler code looks like this:

Code:
private function unloadHandler(event:Event):void {
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onDown);
}

When the container swf unloads the external swf, unloadHandler() gets called, but with the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Where should the keyboard event be removed?

View 9 Replies


Similar Posts:


ActionScript 3.0 :: Static Function That Remove The Object From The Stage As Well As Removing Its Event Listeners?

Oct 12, 2011

I want to make a static function that I can use in all the custom classes.It should be some kill(); function that would remove the object from the stage as well as removing its event listeners. I made it in Document class, and it didn't work. Here's the code:

ActionScript Code:
public static function kill(e:DisplayObject)
{[code].....

View 3 Replies

Actionscript 3 :: When To Remove Event Listeners

Jan 23, 2011

How do you know when you should remove event listeners? For example, I know that if I have a TimerEvent listener, I can safely remove that event when I have stopped and / or deleted my timer. Or, if I have a display object on the stage, and I remove it, I can safely remove any event listeners associated with the display object.

View 1 Replies

ActionScript 3.0 :: How To Remove These Event Listeners

Jan 31, 2009

I've placed listeners on the var "topic_mc" (below), but I'm not sure how to remove them properly:

Code:
private function layoutTopics(modNum:Number, attachTo:MovieClip):void {
topicLength = MainMenu.modArr[modNum].topicArr.length;
if (Interface._ui != null) {

[code]...

doesn't really work - the listeners keep running. How do I call the objects properly to remove the listeners?

View 0 Replies

ActionScript 3.0 :: Remove These Event Listeners?

Feb 2, 2009

I've placed listeners on the var "topic_mc" (below), but I'm not sure how to remove them properly:

Code:
private function layoutTopics(modNum:Number, attachTo:MovieClip):void {
topicLength = MainMenu.modArr[modNum].topicArr.length;
if (Interface._ui != null) {[code]....

doesn't really work - any trace statement I place within the event function will run for infinity. How do I call the objects properly to remove the listeners? Note: I've tried referring to currentTarget instead of target but that doesn't make any difference.

View 7 Replies

ActionScript 3.0 :: Always Remove Event Listeners?

Oct 22, 2010

is it necessarily to add and remove event listeners like so:

Code:

addEventListener(MouseEvent.MOUSE_DOWN,mDown);
function mDown(e:MouseEvent){
removeEventListener(MouseEvent.MOUSE_DOWN,mDown);

[code]....

assuming rapid input, is it really better to do this rather than just let the mouseDown and MouseUp Listeners run all the time? It seems like it would be strenuous to constantly add and remove listeners like this. But this is how i generally see it done..

View 3 Replies

ActionScript 3.0 :: Remove Complex Event Listeners?

Jun 10, 2010

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?

View 7 Replies

ActionScript 3.0 :: Add / Remove Event Listeners Within Functions

Apr 4, 2011

What I am trying to do is, if a user presses keyboard (key 1), picture 1 should FadeIn and if a user presses keyboard (key 2) picture one should FadeOut and picture 2 FadeIn and vice-versa. With the code mentioned below it works fine sometimes if I am not pressing any other key while it is performing one action but sometimes it behaves weird also. What I want AS3 to do is not to take any action or in other words it should not listen to keyboard until it finishes the opening or closing animation of a picture or any other object assigned to the key.
 
stage.addEventListener (KeyboardEvent.KEY_DOWN, KeyDownHandler);
/**///keyboard keycode for 1 & 2var key1:uint = 49;
var key2:uint = 50;
var BG1:Image1 = new Image1();
var BG2:Image2 = new Image2();
[Code] .....

View 14 Replies

ActionScript 3.0 :: Remove Multiple Event Listeners?

Aug 7, 2011

In some cases it is important to remove multiple event listeners in order to reduce CPU time.[code]...

View 3 Replies

Actionscript 3 :: Remove All Event Listeners In Flex?

Aug 4, 2010

Is there some way where I can remove all event listeneres on my components all at once. Expecially when I dont have any prior knowledge of, what all listeners are being attached to my component.

View 4 Replies

Actionscript 3.0 :: Method To Remove All Event Listeners?

Jan 24, 2009

I am creating a large amount of sprites on the fly that have different listeners applied to them -- I want to be able delete these sprites and clear the memory ties that go with them, quick and easy --

Is there a method to detect/remove all listeners on an object without having to check for each one individually?

View 3 Replies

ActionScript 3.0 :: How Important Is It To Remove Event Listeners

Jul 11, 2009

I have a level select screen with about 30 buttons. I created an eventListener for each of these buttons. My question is: When I click a level to enter the game, should I remove all the eventListeners, or would keeping them around not cause any problems?

View 6 Replies

Professional :: Does RemoveChild Remove The Object's Event Listeners

Nov 30, 2010

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?

View 2 Replies

ActionScript 3.0 :: Detect/remove ALL Event Listeners On An Object?

Nov 12, 2009

I'm having problem with garbage collection in a large, not-so-well-written project that I didn't start. I am getting memory leaks -- and want to make sure that all event listeners on the offending objects are removed. I've gone through the code and done what I can, but still ain't happening -- is there a way in AS3 to take an object and see IF it has an event listener, and to REMOVE that listener -- that is, to remove ALL listeners, without knowing what they are? I know if I know what the EVENT TYPE is then I can use hasEventListener() to figure out if it has a listener of that type (although the presupposes I know all the event types being used), but if I don't know the function that it's subscribing to then I can't remove it.

Or is there some other way to simply nullify an object for GC? I've changed all listeners to weak -- but I think (since the offending objects are FLVPlaybacks) that something in the flash internal setup is still listening to my object (I've gleaned this from FB 4 profiler which I've used in external mode). I would just, at this point, like to see what's going on.

View 6 Replies

ActionScript 3.0 :: Remove Event Listeners In Separate Handler Functions?

Sep 17, 2010

I've managed to create a button which on MOUSE_DOWN scales its parent object- it works just like windows in your OS, where you grab the corner and can change the scale of the window.

Here's how I've done it, (minus the MOUSE_DOWN listener)

Code:
function scaleDragHandler(event:Event):void {
var mcWidth:Number = event.target.parent.width;
var mcHeight:Number = event.target.parent.height;

[Code].....

However, it throws the error, "Access to undefined property 'scaleMC'" on the removeEventListener line. My thought was to put another listener for mouse up inside the first, but that sounds wrong

View 2 Replies

Actionscript 3 :: Setting An Object To Null, Automatically Remove All Attached Event Listeners?

Jan 20, 2011

Lately I've found myself constantly writing removeEventListeners everywhere, which makes code quite messy. I know it's a best practice and such, but in general it has no sense. Garbage collector should handle such a simple task by itself, shouldn't it? Is it that hard to remove all listeners automatically when object is set to null?

So I just want to be sure if that's the case. Does setting an object to null, automatically remove all attached event listeners? In my case scenario is like this - I create an object and attach bunch of event listeners to it, then after a while I need to re-initialize this object. Of course setting this object to null is much easier then unbinding every listener by hand. And on most part listeners are anonymous functions, which means that it's not possible without code refactoring. When I simply re-initialize a variable with new I do not get duplicate listeners and such, but I'm not sure that it's previous value, along with all the listeners gets garbage-collected. Is it?

View 2 Replies

ActionScript 3.0 :: Add Event Listeners To MC On Stage?

Nov 6, 2010

I found this code for a contact form at[url]...and it dynamically creates input fields and buttons. I didn't like the dynamically drawn submit and reset buttons, so I added my own MCs(my 'buttons') to the stage.I tried modifying the code and took out the dynamically drawn buttons..However, I cant figure out how to add Event Listeners to the buttons which exist on the stage--Im getting undefined errors...[code]...

View 2 Replies

ActionScript 3.0 :: Set Stage Level Event Listeners?

Apr 7, 2009

As part of a very large project, I want the ability to set stage level event Listeners.
 
This works very easily with MouseEvent s but I can not seem to get it to run properly with KeyboardEvents.  Having google'd this issue I have found very little on the subject.  Mostly noobish type questions of syntax and so forth, but I have seen comment of people claiming to have it work for them.
 
To ensure no issues with any other code, I have made a blank project and blank .as file, with only the event listener code:
 
[Code].... 
 
Click events are always captured and traced correctly, without fail.  Pressing keys appears to do nothing.  If however you mash the keyboards very very quickly, one or two key events will trigger sporadically.  

View 5 Replies

ActionScript 3.0 :: Display What Event Listeners Are Currently On Stage?

Apr 22, 2010

I think I have been generating duplicate Event Listeners behind the scenes which is causing me some problems.
 
I like to find out what Listeners are in existence at a single moment. My code is long so it is hard to go line by line to isolate the issue. It would be faster if I knew what Listeners are were activated.

View 2 Replies

Actionscript 3 :: Add Event Listeners To Global Stage Via Class?

May 24, 2011

i am making a simple game i want to be able to add an keyboard event lisnter within the class constructor. However i am having trouble. i undertsand you have to pass the stage through a listed display object property stage? anyway i am getting errors that do not recognise my event listener keyboard event.

package louiseguchi.game
{
import flash.display.Stage;

[Code]....

View 2 Replies

ActionScript 3.0 :: Adding / Removing Stage Event Listeners

Feb 6, 2009

I'm adding and removing stage event listeners I am relatively new to AS 3 and have been building a liquid layout site unfortunately I do not have a strong grasp of classes and have been doing all of my scripting on the main timeline with encapsulated script within MC's.

basically I am calling on the same functions over and over and those are mostly resize functions which I have added StageEventListeners on the appropriate frames to listen for resize events on that stage now as of now I have literally dozens of these scattered about the site. when testing my site things are running fairly smoothly however I keep getting error messages in my output window that go a little something like this.

[Code]...

View 1 Replies

ActionScript 3.0 :: Adding Event Listeners To Stage Buttons?

May 11, 2010

I have 22 buttons (each named buttoni where i is a number between 0-21...e.g. button0, button1, button2) that I've created and artfully arranged on the stage in my .fla file. The document class for the .fla file is People.as, and in People I'd like to give each button a rollover and click event listener, but I can't figure out how to refer to them using a loop.

Here's my code, which obviously doesn't work:

ActionScript Code:
private function initButtons() : void {
for (var i:int = 0; i<numSquares; i++) {
var thisButton : String = "button" + i;

[Code].....

View 6 Replies

ActionScript 3.0 :: Event Listeners For MCs On Stage And External Classes?

Nov 6, 2010

I found this code for a contact form at msinghinteractive easy-to-use-flash-as3-contact-us-form-class and it dynamically creates input fields and buttons. I didnt like the dynamically drawn submit and reset buttons, so I added my own MCs(my 'buttons') to the stage. I tried modifying the code and took out the dynamically drawn buttons..However, I cant figure out how to add Event Listeners to the buttons which exist on the stage--Im getting undefined errors...The fla is directly associated to a main.as class which just determines the parameters of the .as class it is tied to -to set the size of the Contact form.This is the entire class:

Code:
package{
import classes.*;
import flash.display.*;

[code]....

where btn is the instance name of my submit button MC.My problem is that because my buttons exist on the stage I dont know how to add Event listeners within that class---or rather doing that doesnt work because the listeners are throwing that undefined property errors--I gave them instance names...

View 7 Replies

ActionScript 3.0 :: Stage Event Listeners Causing Error?

Mar 20, 2012

I have just added a menu screen to my game and I get the following error:

ActionScript Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MyGame()

[code].....

View 4 Replies

Flash :: Keeping The Number Of Objects And Event-listeners On Stage As Low As Possible

May 23, 2010

I am creating a site with lots of big scrollable text-boxes in it. Each text-box object contained some text, and two buttons to scroll up/down with. The scroll buttons each had an event listener so the text moved when you clicked them.

These text-boxes were stacked on-top of each other with all except one having an alpha of 0. If I wanted to change which text-box is active I move it to the front and call a small TweenLite animation.

To the left (outside of the text-box objects) I have an object similar to a menu. It also has about 12 or so event-listeners (one for every button).

This turns out cause A LOT of lag an it's very troublesome for my laptop to run it. reduce the number of event-listeners on the stage and also the amount of text-boxes.

What I was thinking was to add the text-boxes using AS so I only have 1 on the stage at a time but I couldn't figure out how to do it. I also thought it might be better to just use 1 big event-listeners and from mouseX and mouseY decide which button the user is trying to push.

View 1 Replies

ActionScript 3.0 :: Attaching Mouse Event Listeners To MovieClip On Stage?

Sep 19, 2009

I have a movieClip on stage, inside is a dynamic textfield, and I have set mc.scaleY = 0;
Code:
mc.scaleY = 0;
mc.buttonMode = true;
mc.mouseChildren = false;
And suddenly everything above and below (on the whole stage) where the movieClip actually is receives mouse, I can see by the button mode. But it only happens with dynamic text, not static.
I have attached the example:

View 8 Replies

Actionscript 3.0 :: Event Listeners - Creates A Bunch Of Movieclips And Sets Them On The Stage?

Feb 20, 2009

I have a loop which creates a bunch of movieclips and sets them on the stage.As I create each one I attatch an eventListener to it.My problem is that when the eventListener fires, the function it calls always works on the first mc added to the stage, not the one that fired the listener.How do I fix this?Here's a bit of the code:

Code: Select allfor (var i:int=0;i<numOfItems;i++) {
item = new Item();
//etc etc[code].....

View 1 Replies

Actionscript 3 :: Android - Attach Mouse Event Listeners To The Stage Or To Individual Sprites?

Aug 16, 2011

In AS3 on Android is it bad from a performance perspective to attach mouse event listeners to individual sprites rather than to the stage? I am writing an app for an Android phone using AS3 in Flash Builder. The app has multiple screens that respond to user touch. The screens are arranged in a hierarchy and show list data so that when you click on an item in a list you are presented with a new screen with a new sub list on it.

I have been using an event listener to detect mouse / touch input and based on something I read that indicated that performance is much better if you keep the number of objects you are listening to to a minimum I have attached the mouse listeners from each screen to the stage object.

This all works fine but I am finding that as I move between screens (and they get popped or pushed onto the dislay stack) I have to keep track of alot of adding and removing listeners to the stage object. If I don't then windows higher up the hierarchy than the current screen keep receiving mouse events.

If I used listeners attached to sprites in each window then when the window was removed from the display even though it is kept in memory (ready to be popped back when a child window is closed) it won't receive any mouse events....

Performance doesn't seem to be impacted using listeners directly on sprites when using my HTC phone to test with, however I obviously don't know what it will be like on other phones. Does anyone have any experience either way or a view on the best approach?

View 1 Replies

ActionScript 3.0 :: Frame Of Nested Object - Remove Only The Event Listeners From Objects Only On Frame 1?

Jan 21, 2011

I have 3 frames each with a movie clip called map_mc. Each different map_mc have different objects that call the CollisionDetect class. Heres whats happening. objects from frame 1 will start freaking out when I goto frame 2. How do I remove only the event listeners from objects only on frame 1?

I have been trying this.currentFrame but the problem is that all the objects are inside map_mc on the first frame so no matter what it will always be 1. On the other hand MovieClip(root).currentFrame will always give me the current frame but wont tell me what the objects frame is relative to the stage.What I want to do is have something to this effect:MovieClip(root).this.currentFrame would output that this object is on frame 1 and MovieClip(root).currentFrame will tell me that the stage is on frame 2 so I can remove the listeners accordingly.

View 3 Replies

ActionScript 3.0 :: Remove An Event Listener On Stage From Outside Class That Set It?

Jul 17, 2009

I am using a component in my application, but it turns out, it's slowing my app down big time b/c it doesnt remove an eventListener on stage for mouse move. Is there a way I can remove this listener? I can't get into the class b/c it's a component and it doesnt have any sort of kill function to call.

View 15 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved