RemoveEventListener Function Will Nicht
Good morning! I am at daggers drawn with the following.
PHP Code:
function onMouseclick(e:MouseEvent):void { if(e.target == buttonHome) { var noEventListener:Array = new Array("buttonFolioDraft", "buttonFolioPhot", "buttonFolio2", disattachEventListener(buttonArray, noEventListener); } }
and:
PHP Code:
function disattachEventListener(array:Array, filter:Array):void { /** Remove EventListener from all elements of an Array that names are matching one of the filter Strings **/ var disattach:Array = new Array(); for(var i:uint = 0; i < array.length; i++) { for(var j:uint = 0; j < filter.length; j++) { if(array[i].name.substring(0, filter[j].length) == filter[j]) { trace("yuppy!"); disattach.push(array[i]); } } } for(var i:uint = 0; i < disattach.length; i++) { disattach[i].removeEventListener(MouseEvent.ROLL_OVER, setActiveWindow(), false); disattach[i].removeEventListener(MouseEvent.ROLL_OUT, setActiveWindow()); disattach[i].removeEventListener(MouseEvent.CLICK, setActiveWindow()); disattach[i].buttonMode = false; } }
function setActiveWindow():void { // just empty atm trace("here: ActiveWindow"); }
The output gives me the following:
TypeError: Error #2007: Parameter listener must be non-null. at flash.events::EventDispatcher/removeEventListener() at 09_fla::MainTimeline/disattachEventListener() at 09_fla::MainTimeline/onMouseclick()
Since I am completely sure I added to each of those MCs each three EventListener, I checked out EventDispatcher in the API lang. ref. for removeEventlistener but no matter beeing unsure I understood what the third parameter now really achieves, I tried both states with the same result. Best regards, zoimt
KirupaForum > Flash > ActionScript 3.0
Posted on: 06-21-2008, 09:18 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
RemoveEventListener() For An Anonymous Function
I have an event listener with an anonymous function literal, rather than a function reference. What I am trying to figure out is how to remove that event listener.
Obviously, I need a reference to the anonymous function, so the two functions are ===. But, something is going wrong... it just doesn't work, ad this situation doesn't generate any feedback to tell me what might be wrong.
There is some good info here, but not a clear explanation.
Code:
private static var _myFunc:Function;
public static function addCreditsToolTip(clip:DisplayObject):void
{
clip.addEventListener("rollOver",
_myFunc = function():void
{
trace("yay!");
});
trace(_myFunc); //"function Function() {}" < PERFECT!
clip.removeEventListener("rollOver", _myFunc); // < this doesn't work.
}
RemoveEventListener() For An Anonymous Function
I have an event listener with an anonymous function literal, rather than a function reference. What I am trying to figure out is how to remove that event listener.
Obviously, I need a reference to the anonymous function, so the two functions are ===. But, something is going wrong... it just doesn't work, ad this situation doesn't generate any feedback to tell me what might be wrong.
There is some good info here, but not a clear explanation.
Code:
private static var _myFunc:Function;
public static function addCreditsToolTip(clip:DisplayObject):void
{
clip.addEventListener("rollOver",
_myFunc = function():void
{
trace("yay!");
});
trace(_myFunc); //"function Function() {}" < PERFECT!
clip.removeEventListener("rollOver", _myFunc); // < this doesn't work.
}
Kann Meinen Flashfilm Nicht Auf Mac Sehen
bin flash anfänger, hoffe das schrekt nicht ab.
habe eine hompage erstellt die wunderbar läuft, solange ich sie mir mit einem pc im internet anschaue.
leider ist es macusern nicht möglich diese seite zu sehen.
was mache ich falsch, wie kann ich das ändern???
bitte kann mir jemand helfen!!!!!!!!!!
Help With - RemoveEventListener
I have a button that uses 2 actions
MOUSE_DOWN - uses an action
MOUSE_UP - uses another action
what I want to do is,
when it's MOUSE_UP
I need to remove listener and clear the action that is used in MOUSE_DOWN.
Here is the I used; which works until MOUSE_UP is used.
forward_btn.addEventListener(MouseEvent.MOUSE_DOWN , fastForwardTimeline);
function fastForwardTimeline(e:MouseEvent):void {
stage.addEventListener(Event.ENTER_FRAME, forwardTimeline);
function forwardTimeline(e:Event):void {
nextFrame();
nextFrame();
nextFrame();
}
}
//// upto here there is no problem , it works,
/// below is the code that is supposed to removeListener but it doesnt work.
forward_btn.addEventListener(MouseEvent.MOUSE_UP, playTheTimeline);
function playTheTimeline(e:MouseEvent):void {
stage.removeEventListener(Event.ENTER_FRAME, forwardTimeline);
play();
}
please help.
Thanks in advance.
RemoveEventListener
Hi there
I am trying to remove an event when the timeline move to another frame than 20, but obviously there is sth wrong.
Any ideas ?
ActionScript Code:
this.addEventListener(Event.ENTER_FRAME, slideFondBlanc2);
function slideFondBlanc2($evt:Event):void
{
// lines codes
if (this.currentFrame!=20) {
removeEventListener(Event.ENTER_FRAME, slideFondBlanc2);
}
};
AS3 - RemoveEventListener
Hi there.
Got this code that creates a sprite.
Need to make it follow the mouse on MOUSE_DOWN and stop on MOUSE_UP.
Problem is that I can't stop the MOUSE_MOVE Listener given to the stage.
Any Help...?
Here is my code:
import gs.TweenLite;
import fl.motion.easing.*
this.stop ();
function addCircle ( _sp:Sprite, x:uint, y:uint, radius:uint ):void
{
_sp.graphics.clear ();
_sp.graphics.beginFill(0x666666);
_sp.graphics.drawCircle(x, y, radius);
_sp.graphics.endFill();
}
var sp:Sprite = new Sprite();
addCircle (sp, 0, 0, 20);
stage.addChild(sp);
function moveSprite ( _sp:Sprite ):void
{
TweenLite.to(_sp, 1,
{
x:mouseX,
y:mouseY,
ease:Sine.easeOut
});
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void {
moveSprite (sp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, function ():void {
moveSprite (sp);
});
});
stage.addEventListener(MouseEvent.MOUSE_UP, function ():void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveSprite);
});
Thanks
AS3 - RemoveEventListener
Hi there.
Got this code that creates a sprite.
Need to make it follow the mouse on MOUSE_DOWN and stop on MOUSE_UP.
Problem is that I can't stop the MOUSE_MOVE Listener given to the stage.
Any Help...?
Here is my code:
import gs.TweenLite;
import fl.motion.easing.*
this.stop ();
function addCircle ( _sp:Sprite, x:uint, y:uint, radius:uint ):void
{
_sp.graphics.clear ();
_sp.graphics.beginFill(0x666666);
_sp.graphics.drawCircle(x, y, radius);
_sp.graphics.endFill();
}
var sp:Sprite = new Sprite();
addCircle (sp, 0, 0, 20);
stage.addChild(sp);
function moveSprite ( _sp:Sprite ):void
{
TweenLite.to(_sp, 1,
{
x:mouseX,
y:mouseY,
ease:Sine.easeOut
});
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void {
moveSprite (sp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, function ():void {
moveSprite (sp);
});
});
stage.addEventListener(MouseEvent.MOUSE_UP, function ():void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveSprite);
});
Thanks
RemoveEventListener
I'm having trouble properly removing an eventListener that keeps looping.
Here's my code:
Code:
var speed:Number = 1.1;
button.addEventListener(MouseEvent.CLICK, splitBox);
function splitBox(evt:MouseEvent):void {
button.addEventListener(Event.ENTER_FRAME, ease);
}
function ease(evt:Event):void {
Box1_mc.x = 140 - (140 - Box1_mc.x) / speed;
Box2_mc.x = 400 - (400 - Box2_mc.x) / speed;
if (Box1_mc has reached its x-coordinate destination) {
Box1_mc.x = it's final x-coordinate destination
button.removeEventListener(Event.ENTER_FRAME, ease);
//stop running the 'ease' function
}
trace(Box1_mc.x); //when I trace I get
an infinate number loop of 140 eventually, the
coordinate where it's supposed to stop
}
button.buttonMode = true;
This would basically end the loop, and rest Box1_mc after easing into position. I would then apply the same concept to Box2_mc. I'm still a beginner, a simple explanation and help would be great.
RemoveEventListener
I've got this global function that I want to use throughout my entire project. Every time I want to load an image, it hits this function and this function fades it in.
My question is about removing the loading event, and just wondering if doing it this way actually removes the eventlistener:
Code:
public static function FadeInContentAfterLoad(e:Event):void{
e.target.content.alpha = 0;
Tweener.addTween( e.target.content, { alpha: 1, time:2, transition:"easeOutQuint"} );
e.target.content.parent.contentLoaderInfo.removeEventListener(Event.COMPLETE, FadeInContentAfterLoad);
}
And here's a usage example:
Code:
ProjectPlaneImgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, ComTools.FadeInContentAfterLoad);
Is there a way to monitor events to see if it actually removed it?
RemoveEventListener
Hey everyone. I am trying to do something that seems pretty simple. But, being fairly new to AS3.0, I must be missing something stupid. I have several 3D blocks that follow your mouse when you move. When you click on a box, it zooms in to one of them and I want to remove the mouse listener. Pretty simple, eh? Well, it's not working. Can anyone take a look and see what I'm missing.
The offending line is at the bottom. I keep getting the error:
"1120: Access of undefined property onEnterFrame"
I'm guessing this is a scope issue and I'm just addressing it wrong but I've tried everything.
Thanks for your help!
Code:
public class ProMax extends Sprite
{
private var viewport: Viewport3D;
private var scene: Scene3D;
private var camera: Camera3D;
private var renderer: BasicRenderEngine;
private var picCube: PictureCube;
private var mat: BitmapFileMaterial;
private var matList: MaterialsList;
private var cubes: Array;
private var boxWidth: Number = 300;
private var boxHeight: Number = 500;
private var boxDepth: Number = 10;
public function ProMax():void
{
viewport = new Viewport3D(800, 600, false, true);
addChild(viewport);
scene = new Scene3D();
camera = new Camera3D();
renderer = new BasicRenderEngine();
camera.y = 200;
cubes = new Array();
AddCube(0, 0);
AddCube(-400, 600);
AddCube(-600, 300);
AddCube(400, 100);
AddCube(800, 250);
AddCube(1200, 400);
AddCube(-500, 600);
AddCube(-1100, 250);
AddCube(-1500, 600);
function onEnterFrame(e:Event):void
{
camera.x = mouseX - 400;
renderer.renderScene(scene, camera, viewport);
}
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function AddCube(nx:Number, ny:Number) {
var pCube:Cube;
var matFront:BitmapFileMaterial = new BitmapFileMaterial("xwingskin.jpg");
matFront.doubleSided = true;
matFront.interactive = true;
var matLeft:ColorMaterial = new ColorMaterial(0x222222);
matLeft.doubleSided = true;
var matRight:ColorMaterial = new ColorMaterial(0x444444);
matRight.doubleSided = true;
var matTop:ColorMaterial = new ColorMaterial(0x666666);
matTop.doubleSided = true;
var matBottom:ColorMaterial = new ColorMaterial(0x888888);
matBottom.doubleSided = true;
var matBack:ColorMaterial = new ColorMaterial(0xaaaaaa);
matBack.doubleSided = true;
matList = new MaterialsList();
matList.addMaterial(matBack, "front");
matList.addMaterial(matFront, "back");
matList.addMaterial(matLeft, "left");
matList.addMaterial(matRight, "right");
matList.addMaterial(matBottom, "bottom");
matList.addMaterial(matTop, "top");
pCube = new Cube(matList, boxWidth, boxDepth, boxHeight, 1, 1, 1);
pCube.x = nx;
pCube.z = ny;
scene.addChild(pCube);
cubes.push(pCube);
pCube.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onPress);
function onPress(e:InteractiveScene3DEvent):void
{
// THIS IS THE LINE THAT FAILS
stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
if (camera.z != -1000) {
Tweener.addTween(camera, {x: e.target.x, time: 2, transition:"easeInOutQuint" } );
Tweener.addTween(camera, {z: -1000, time: 2, transition:"easeInOutQuint" } );
} else {
Tweener.addTween(camera, {x: e.target.x, time: 2, transition:"easeInOutQuint" } );
Tweener.addTween(camera, {z: e.target.z - 200, time: 2, transition:"easeInOutQuint" } );
}
}
}
}
I Can't RemoveEventListener
how i can remove "removeEventListener" clicked mc?
this is my code.
Code:
var loop=function()
var mytime:Timer=new Timer(1500)
mytime.addEventListener(TimerEvent.TIMER,newBall)
mytime.start()
function newBall(e:TimerEvent):void{
var ball:MovieClip=new MovieClip()
ball.graphics.beginFill(0xFF8800)
ball.graphics.drawCircle(50,150,30)
addChild(ball)
anim(ball)
}
function anim(cmc){
cmc.addEventListener(Event.ENTER_FRAME,loop)
function loop(e:Event):void{
e.target.x+=2
}}
addEventListener(MouseEvent.MOUSE_DOWN,mdown)
function mdown(e:MouseEvent):void{
var cname= getChildByName(e.target.name)
trace(cname.name)
//removeChild(cname)
cname.removeEventListener(Event.ENTER_FRAME,loop)//problem line
}
RemoveEventListener On End Of A Mp3.
Hi,
I'm having some trouble with my flash.
I would like to have a eventlistener start when a sound starts... and then ends when the sound stops.
I've got it to work when the sound starts, becouse play is a default. but i cant seem to find how flash knows when a sound is finishd and if it possible to add a function when the sound is finishdplaying.
Is this possible? if so how?
like
Sound.Stopped () or something?
So, I don't want to make the sound stop, but I want something to happen WHEN the sounds finishes
Regards,
Tic
RemoveEventListener (again)
It's evident that I do not understand what or how or everything about removing event listeners.
For example:
scrollLeft_mc.addEventListener(MouseEvent.MOUSE_DOWN, leftscroll);
function leftscroll(evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, eventleft);
function eventleft(evt:Event):void {
grey.x -= 10;
}
}
scrollLeft_mc.addEventListener(MouseEvent.MOUSE_UP, leftstop);
function leftstop(evt:MouseEvent):void {
removeEventListener(Event.ENTER_FRAME, eventleft);
trace("stop");
}
I get an "access of undefined property eventlist" error.
Why?
Basically, I am trying to get a movieclip "grey" to move across the screen when you click and hold a button. Then "grey" should stop when you release the button.
RemoveEventListener()
hi whats the correct way of using removeEventListener() is the sample below? It works but if throws an error because I'm not pointing it towards a function, but i don't want it to run a function. whats the solution?
Code:
stage.addEventListener(MouseEvent.MOUSE_UP, movieClipStop);
function movieClipStop(event:MouseEvent):void
{
movieClip.stopDrag();
//only run the function if the mouse is over the movieClip
movieClip.addEventListener(MouseEvent.MOUSE_OVER, changeVolume);
function changeVolume(event:MouseEvent):void
{
//------ do something special
}
//------ clear the uneeded event listener
movieClip.removeEventListener(MouseEvent.MOUSE_OVER);
}
Debugging RemoveEventListener
I want to know whether the EventListener is added or removed from some objects.
Is there any easy way to know that by a trace command or by a debbuger?
RemoveEventListener And Delegate
I can get events from an event dispatcher by
Code:
mouth.addEventListener ("finishedTalking",Delegate.create(this, this.shutUp))
and this.shutUp gets called nicely when mouth has finished talking.
In my sitaution mouth conitues to fire off finishedTalking events but I want ot ignore them so
Code:
private function shutUp()
{
mouth.removeEventListener ("finishedTalking", ?????);
}
The ????? bit here is the tricky bit. It should be a reference to the listener, but what is my listener?
I've tried this, this.shutUp and Delegate.create(this, this.shutUp) and I can't stop the events coming.
There are work arounds but this sort of issue is in a lot of places in the code I'm working on so I want a proper fix.
RemoveEventListener Not Working
when i test the following code i get an error...
TypeError: Error #1006: removeEventListener is not a function.
at MethodInfo-7()
... I don't know why i'm getting this, does anyone have any ideas?
Quote:
//functions called by CLICK of buttons (Decision 1)
function vid1Play(CLICK:Event):void{
videoStream.play("vid1.flv");
//Monitor the video
this.addEventListener(Event.ENTER_FRAME, checker);
function checker(ENTER_FRAME:Event):void{
if (videoStream.time >= 1.7){
trace("Video is finished!");
AddChoiceGen2(null);
this.removeEventListener(Event.ENTER_FRAME, checker);
}
}
}
RemoveEventListener Does Not Work In As3?
Hello everyone
I'm a poor man suffering as2 to as3 migration-itis
I have a fla with this code. It puts a button on the stage and adds rollover-rollout listeners to it:
____________________________________________
Code:
package ugh{
import flash.display.*
import flash.events.*
public class ugh extends Sprite{
public function ugh(){
function onOver(e:MouseEvent){
var d=e.target
trace("in:"+d)
var g=new Go(d)
}
function onOut(e:MouseEvent){
var d=e.target
trace("out:"+d)
var g=new Go(d)
}
var b=new button()
addChild(b)
b.addEventListener(MouseEvent.MOUSE_OVER,onOver)
b.addEventListener(MouseEvent.MOUSE_OUT,onOut)
}// fin ugh
}
}
_____________________________________
And I have this static class, which is used when rollovers are detected
_______________________________
Code:
package{
import flash.display.*
import flash.events.*
public class Go{
public function Go(loque:Sprite){
if(loque.hasEventListener(Event.ENTER_FRAME)){
trace("quit")
loque.removeEventListener(Event.ENTER_FRAME, procede)
}else{
trace("add")
loque.addEventListener(Event.ENTER_FRAME,procede)
}
var k=0
function procede(e:Event){
trace("procede:"+e.target+" k:"+k)
k++
if(k>10){
loque.removeEventListener(Event.ENTER_FRAME, procede)
}
}// fin procede
}// fin go
}// fin class
}// package
_______________________________________________
If you rollOver the button, a count is traced (1, 2, 3...); a number per frame, up to ten.
If you rollOut the button before the count ends, the enterFrame is detected but its not removed, despite the removeEventListener, and the count does not stop. I already tried loque.removeEventListener("enterFrame", procede) instead of loque.removeEventListener(Event.ENTER_FRAME, procede), but no way
any ideas?
thanks!
Issue With RemoveEventListener
Hi
I'm trying to develop a generic function that will make a button pulse onRollOver and revert to its original state onRollOut.
Here's my code:
package
{
import flash.display.*
import flash.events.*
public class polygon extends MovieClip
{
var growing:Boolean = true;
public function polygon()
{
addEventListener(MouseEvent.ROLL_OVER, begin);
addEventListener(MouseEvent.ROLL_OUT, end);
}
private function begin(event:MouseEvent):void
{
event.target.addEventListener(Event.ENTER_FRAME, pulse);
}
private function pulse(event:Event):void
{
if (growing) {
if (this.scaleX < 1.3) {
this.scaleX += 0.1;
this.scaleY += 0.1;
} else {
growing = false;
}
} else {
if (this.scaleX > 1) {
this.scaleX -= 0.1;
this.scaleY -= 0.1;
} else {
growing = true;
}
}
}
private function end(Event:MouseEvent):void
{
this.scaleX = 1;
this.scaleY = 1;
this.removeEventListener(Event.ENTER_FRAME, pulse);
}
}
}
The rollOver works fine, but when I roll out the button doesn't revert to its original state, but continues to pulse.
I'm sure it's a problem with the way I'm referencing the removeEventHandler - and equally sure there's a simple fix - but can anyone help me out?
Thank you in advance
Standard
RemoveEventListener Problem... I Think
Hey all,
well my first thread yay!
anyway, I have som problems with an animated dropdown-menu im creating with as3. so short version as follows:
Im trying to make a button that goes to a specific frame on MOUSE_OVER and to go to another frame on MOUSE_OUT. This would have been no problem if it was only a matter of 2 frames but I want it to go to a frame that is the beginning of a Tween.
At the beginning of the timeline I use this code on the button I call "starthere":
ActionScript Code:
//Frame events
stop();
//Frame events end
//button starthere
starthere.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
gotoAndPlay(2);
}
);
//button starthere end
Then at the end of the tween I want the button to go to another frame at MOUSE_OUT so I use this code in that frame:
ActionScript Code:
//Frame events
stop();
//Frame events end
//button starthere
starthere.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
gotoAndPlay(27);
}
);
//button starthere end
Now all that works fine the first time, but the second time, that is when the timeline reaches it's last frame and then jumps back to the first frame again, it wont work propably. It's like it uses ALL the code throughout the entire movie, that is eventhough it havent yet reached frame no.26 (end of tween) where the second code is, it still uses that code in the frames before 26. So if I say drag the mouse away from the button in frame 10 it jumps to frame 27.
Does any of this make sense? I've tried to use the removeEventListener(); but i cant get it to work... i need help... thnx
/ Tovedal
RemoveEventListener Does Not Work
Hi,
I have a button that has a MouseEvent listener but when I click the button the second time the click event is not being dispatched.
My code:
refBtn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
refBtn.removeEventListener(MouseEvent.CLICK, onClick);
empWrap.addChild(refWrap);
refWrap.x = 20;
}
When I click the refBtn the first time, it's calling the onClick function, but the second time, nothing happens.
Can someone please help?
Thanks,
Cgull
RemoveEventListener Trouble
I'm pretty new to Actionscript 3 and I'm having a bit of trouble with the removeEventListener function. I've searched but haven't had much luck finding an answer.
I've got this line:
Code:
goback.addEventListener(MouseEvent.MOUSE_DOWN, function() {GoBack2(p);}, false);
And then I have this line:
Code:
goback.removeEventListener(MouseEvent.MOUSE_DOWN, function() {GoBack2(p);}, false);
The removeEventListener does not appear to be working. Any help would be greatly appreciated.
Thanks
RemoveEventListener Problem
Hy there,
i got a drag and drop function.
i set up a function, that checks if the target was hit or missed.
If hit was true, than a eventListener is added,if hit was missed the eventListerner should be removed.
ActionScript Code:
if (....)
{
event.currentTarget.addEventListener(MouseEvent.MOUSE_OVER,setOver);
event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT,setOut);
}
else
{
event.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER,setOver);
event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,setOut);
}
When i drop my mc on the target the function works, but if i drag that mc out of the target the Mouse-function still is available.
Did i use removeEventListener in a wrong way?
RemoveEventListener Of An External SWF
Dear all,
I have come accross a problem where my loops are stacking and therefore are using more and more memory.
On my mainstage, when I remove a child (an external SWF), I wish to remove the ENTER_FRAME listeners from that external SWF.
I have realized that removing a Child is not enough because the loops stay on stage.
How do I this ?
Thank you
Aurel
Problem With RemoveEventListener
Hi guys, i have an annoying problem. I have a mc that i use as a button. I have an external class that controls the button and adds interactivity to it, here's part of the code:
Code:
package
{
import flash.display.*;
import flash.text.*;
import flash.geom.ColorTransform;
import flash.events.*;
public class BtnCuadSelect extends MovieClip
{
public function BtnCuadSelect():void
{
this.mouseChildren=false;
this.buttonMode=true;
init();
}
public function init():void
{
addEventListener(MouseEvent.MOUSE_OVER,over);
addEventListener(MouseEvent.MOUSE_OUT ,up);
addEventListener(MouseEvent.MOUSE_DOWN ,down);
}
private function over(evt:MouseEvent):void
{
//actions...
}
private function up(evt:MouseEvent):void
{
//actions...
}
private function down(evt:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_OVER,over);
removeEventListener(MouseEvent.MOUSE_OUT ,up);
removeEventListener(MouseEvent.MOUSE_DOWN ,down);
this.buttonMode=false;
}
}
}
The problem is, i want the btn that, when clicked, remain inactive.That's why I remove all the listeners in the class. HOWEVER, it still functions as a button, I mean the functions haven't been removed at all after I click it. What's wrong here?? Why are the functions still there, if I have removed them when clicked at the btn??? :S
Any help, please?
RemoveEventListener And Delegates
I am having trouble removing listeners that have been added using the Delegate.create() method.
In the following code, can someone tell me how to properly remove these listeners?
note: Application is a singelton class that extends mx.screens.Form. So, Application.getInstance() is a static method that returns a refernces to the one and only root form.
----
Attach Code
public function makeActive(active:Boolean):Void {
trace(this._drawingName + " active = " + active);
if (active) {
Application.getInstance().addEventListener("onMouseDown", Delegate.create(this, this.mouseDowm));
Application.getInstance().addEventListener("onMouseMove", Delegate.create(this, this.mouseMove));
Application.getInstance().addEventListener("onMouseUp", Delegate.create(this, this.mouseUp));
} else {
Application.getInstance().removeEventListener("onMouseDown", Delegate.create(this, this.mouseDowm));
Application.getInstance().removeEventListener("onMouseMove", Delegate.create(this, this.mouseMove));
Application.getInstance().removeEventListener("onMouseUp", Delegate.create(this, this.mouseUp));
}
}
RemoveEventListener - Problem
Hi. please check the code, i can't remove the event listener like this,
when the first button click i need to set the new event listener for the btn_mc and remove the previus listners,
please help with this
set_mc.addEventListener(MouseEvent.MOUSE_UP,setclicks);
function setclicks(event:MouseEvent):void
{
setBtn()
}
function setBtn()
{
if(btn_mc.hasEventListener(MouseEvent.MOUSE_UP) )
{
btn_mc.removeEventListener(MouseEvent.MOUSE_UP,clicks);
}
btn_mc.addEventListener(MouseEvent.MOUSE_UP,clicks);
function clicks(event:MouseEvent):void
{
trace("lol");
}
}
RemoveEventListener Not Working
I have several movie clips that are listening for roll over and roll out events. When the movie clips are clicked, I need to remove their roll over and roll out listeners so that they don't trigger when the mouse rolls off.
currSelected.removeEventListener(MouseEvent.ROLL_OVER, fadeChapterIn);
currSelected.removeEventListener(MouseEvent.ROLL_OUT, fadeChapterOut);
The above code does not work. Neither does...
e.target.removeEventListener(MouseEvent.ROLL_OVER, fadeChapterIn);
e.target.removeEventListener(MouseEvent.ROLL_OUT, fadeChapterOut);
If I reference a specific clip, such as...
chapter2_mc.removeEventListener(MouseEvent.ROLL_OVER, fadeChapterIn);
chapter2_mc.removeEventListener(MouseEvent.ROLL_OUT, fadeChapterOut);
then it works, but I have to create a new function for each clip and I'd rather be able to reuse one function.
Attach Code
// -------------------------------------------------------------------------------------- \
// Sets which chapter button was previously selected when a new \
// chapter button is clicked \
// -------------------------------------------------------------------------------------- \
var prevSelected:MovieClip = chapter1_mc;
var currSelected:MovieClip = chapter1_mc;
function selectChapter(e:MouseEvent):void
{
currSelected = MovieClip(e.target);
if (prevSelected != currSelected)
{
resetChapter(prevSelected);
prevSelected.addEventListener(MouseEvent.ROLL_OVER, fadeChapterIn);
prevSelected.addEventListener(MouseEvent.ROLL_OUT, fadeChapterOut);
}
currSelected.removeEventListener(MouseEvent.ROLL_OVER, fadeChapterIn);
currSelected.removeEventListener(MouseEvent.ROLL_OUT, fadeChapterOut);
prevSelected = currSelected;
}
Edited: 08/19/2008 at 11:36:08 AM by bhuber7
How Do I Call RemoveEventListener()?
I have a firework class, which fades over time and finally removes itself from the display parent.
ActionScript Code:
package {import flash.display.MovieClip;import flash.display.Sprite;import flash.events.Event;import flash.events.EventDispatcher; public class Firework_mc extends MovieClip {private var lifetime:int; // lifetime, measured in age events public function Firework_mc( r:Number, lifetime:int ){width = r * 2;height = r * 2;this.lifetime = lifetime;addEventListener( Event.ENTER_FRAME, fade );} private function fade( event:Event ):void {alpha -= 1 / lifetime;if ( alpha <= 0 ){parent.removeChild( this );}}}}
However, the EnterFrame event listener stays around, so after a Firework_mc removes itself from the display, I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Firework_mc/::fade()
What is the syntax for removing the EnterFrame listener? I have looked around and attempted to use EventDispatcher.removeEventListener( Event.ENTER_FRAME, this ); but it gives me the following error:
1061: Call to a possibly undefined method removeEventListener through a reference with static type Class.
Thanks in advance.
RemoveEventListener Does Not Work In As3?
Hello everyone
I'm a poor man suffering as2 to as3 migration-itis
I have a fla with this code. It puts a button on the stage and adds rollover-rollout listeners to it:
____________________________________________
Code:
package ugh{
import flash.display.*
import flash.events.*
public class ugh extends Sprite{
public function ugh(){
function onOver(e:MouseEvent){
var d=e.target
trace("in:"+d)
var g=new Go(d)
}
function onOut(e:MouseEvent){
var d=e.target
trace("out:"+d)
var g=new Go(d)
}
var b=new button()
addChild(b)
b.addEventListener(MouseEvent.MOUSE_OVER,onOver)
b.addEventListener(MouseEvent.MOUSE_OUT,onOut)
}// fin ugh
}
}
_____________________________________
And I have this static class, which is used when rollovers are detected
_______________________________
Code:
package{
import flash.display.*
import flash.events.*
public class Go{
public function Go(loque:Sprite){
if(loque.hasEventListener(Event.ENTER_FRAME)){
trace("quit")
loque.removeEventListener(Event.ENTER_FRAME, procede)
}else{
trace("add")
loque.addEventListener(Event.ENTER_FRAME,procede)
}
var k=0
function procede(e:Event){
trace("procede:"+e.target+" k:"+k)
k++
if(k>10){
loque.removeEventListener(Event.ENTER_FRAME, procede)
}
}// fin procede
}// fin go
}// fin class
}// package
_______________________________________________
If you rollOver the button, a count is traced (1, 2, 3...); a number per frame, up to ten.
If you rollOut the button before the count ends, the enterFrame is detected but its not removed, despite the removeEventListener, and the count does not stop. I already tried loque.removeEventListener("enterFrame", procede) instead of loque.removeEventListener(Event.ENTER_FRAME, procede), but no way
any ideas?
thanks!
RemoveEventListener Extension ?
Okay, I have to admit that I'm very puzzled as to why this isn't a native method in Actionscript3.
Either way, I was wondering if anyone had any tips on how to create something like;
clip.removeAllEventListeners();
Ie: something that will clear all listeners without having to specify them one by one with event and callback specified.
Any feedback is appreciated.
Problem With RemoveEventListener
i'm having problem with removing event listener from movieClip
can someone look at the code please... im in the proces of migration from as2-as3
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
//-------------------------------------------------------------------------------
// blueDot
function createGrid():void {
var gridHolder:MovieClip = new MovieClip();
gridHolder.x = 20;
gridHolder.y = 20;
var gridMovies:Array = new Array();
var xLoopNum:int = 2;
var yLoopNum:int = 2;
for (var j:int = 0; j<yLoopNum; j++) {
for (var i:int = 0; i<xLoopNum; i++) {
var tempDot:MovieClip = new MovieClip();
tempDot.addChild(new blueDot());
tempDot.name = "dot_"+i;
tempDot.x = i*25;
tempDot.y = j*25;
tempDot.rotationInterval = Math.random()*4+1;
tempDot.addEventListener(MouseEvent.CLICK,handleDo tClick);
tempDot.addEventListener(Event.ENTER_FRAME, handleDotRotation);
gridHolder.addChild(tempDot);
gridMovies.push(tempDot);
}
}
stage.addChild(gridHolder);
}
function handleDotClick(evt:MouseEvent):void {
var tempDot:MovieClip = MovieClip(evt.target);
tempDot.removeEventListener(Event.ENTER_FRAME, handleDotRotation);
//evt.target.parent.removeChild(evt.target);
}
function handleDotRotation(evt:Event):void {
var tempDot:MovieClip = MovieClip(evt.target);
tempDot.rotation += tempDot.rotationInterval;
}
//-------------------------------------------------------------------------------
createGrid();
RemoveEventListener Problems
Hi,
I am having some problems with removing events , here is the code.
Code:
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragIt);
rect_mc.addEventListener(MouseEvent.CLICK, clickIt);
function dragIt(eve:MouseEvent):void
{
rect_mc.startDrag(true);
eve.updateAfterEvent();
}
function clickIt(eve:MouseEvent):void
{
trace(eve.target.name + " is clicked");
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragIt);
}
can you please tell me why the event on stage is not removed, even if i click like thousand times.....
thanks is advance.....
MOUSE_WHEEL RemoveEventListener Problem
Hey Everyone,
I'm having trouble removing the event listener for a MOUSE_WHEEL and I'm hoping someone can tell me what I'm doing wrong.
My stage is setup with a scrolling window area that gets populated on the fly. A scroll bar is setup on the stage and depending on the height of the window the scroll bar should be visible or not. Along with the scroll bar, there is a MOUSE_WHEEL event listener that should be added or removed accordingly.
Here is the function that checks the window height (content_window.dynContainer.height) and either adds or removes the MOUSE_WHEEL listener.
function check_container_h(){
if(content_window.dynContainer.height<content_wind ow.masker.height){
content_window.sb.visible=false;
if(stage.hasEventListener(MouseEvent.MOUSE_WHEEL)) {
stage.removeEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
trace("Mouse Wheel Removed")
}
}else{
content_window.sb.visible=true;
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
}
}
The function is adding the MOUSE_WHEEL listener without issue, but it will not remove it. The trace is printing out to let me know that the listener should have been removed, but it is not being removed.
Any thoughts?
Thanks in advance.
Basic RemoveEventListener Question
Hey, new to AS3 here and trying to work w/ event listeners.
I have a modal window type sprite that contains a few different buttons. All of the buttons have their own event listeners to handle the over, off and click states.
In terms of best memory management, do I have to manually remove all of the event listeners for each button when the modal window closes? Or are all listeners automatically removed (or made eligible for garbage collection) once the modal window sprite is removed from the display list and its instance set to null?
Thanks!
Help With RemoveEventListener(), No Error Found.
Hi making a simple OOP mousescroller. It's capable of scrolling by the bar on the right and then clicking on images mask and holding down and moving Y axis will scroll it as well but that part doesn't work.
Here's the code
ActionScript Code:
package com.utils.ui
{
import flash.events.*;
import flash.display.*;
import caurina.transitions.*;
public class ScrollBox extends MovieClip
{
private var easing:Number = 0.09;
private var targetY:Number ;
private var maxY:Number;
private var vy:Number;
private var flag:Boolean = false;
public function ScrollBox()
{
masker.buttonMode = true;
sb.addEventListener(ScrollerEvents.VALUE_CHANGED, sbChange);
//masker.addEventListener(MouseEvents.VALUE_CHANGED, mpChange);
masker.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
masker.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
//stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
//stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseDown);
}
private function stageMouseUp(e:MouseEvent):void
{
trace("stageUp");
masker.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseDown);
masker.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
//stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseMove);
}
private function onMouseUp(e:MouseEvent):void
{
trace("up");
//masker.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
masker.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
private function stageMouseDown(e:MouseEvent):void
{
}
private function onMouseDown(e:MouseEvent):void
{
trace("down");
masker.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function sbChange(e:ScrollerEvents):void
{
Tweener.addTween(content1, {y:(-e.scrollPercent *(content1.height-masker.height)), time:.2});
}
private function onEnterFrame(e:Event):void
{
masker.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove (e:Event):void
{
if(flag)
{
trace(flag);
//var centerPoint:Number = masker.height /2;
targetY = mouseY ;
maxY = content1.height - masker.height;
var vy:Number = (targetY - content1.y) * easing;
content1.y += vy;
}else{
}
trace("move");
}
}
}
Now for some reason when I do a masker.removeEventlistener(): on MouseEvents and Enterframe events, they don't get removed for some reason. Thanks in advance
RemoveEventListener Is Not Working On If/else Condition
Hello All,
It is very ridiculous that I can't remove a simple listener method :). I think this is a common problem
When I am using removeEventListener manually, i.e outside the condition its working fine, but whenever I am using it inside the if/else condition it is adding the listener in "true" mode but not removing in the "false" mode.
here is my code:
if (proAlign == true) {
trace("align Option = " + proAlign + " -- " + "this is true part");
centerAlignButton.buttonMode=true;
bookPocketAlignButton.buttonMode=true;
centerAlignButton.addEventListener(MouseEvent.CLICK,centreAlign);
bookPocketAlignButton.addEventListener(MouseEvent.CLICK,pocketAlign);
} else {
centerAlignButton.removeEventListener(MouseEvent.CLICK,centreAlign);
bookPocketAlignButton.removeEventListener(MouseEvent.CLICK,pocketAlign);
centerAlignButton.buttonMode=false;
bookPocketAlignButton.buttonMode=false;
}
RemoveEventListener Not Deactivating Buttons?
ActionScript Code:
nextBTN.addEventListener(MouseEvent.CLICK, nextThumbs);private function nextThumbs(event:MouseEvent):void{ deactivateBTNs(); }private function deactivateBTNs():void{ nextBTN.removeEventListener(MouseEvent.CLICK, nextThumbs); }
What's going on here? nextBTN is still activated...
Tweens + RemoveEventListener = Error;
Hello.
I'll get right to the error, and describe how I came across it further below. Removing event listeners from tweens causes errors. Does anyone know why?
Code:
import fl.transitions.Tween;
import fl.transitions.easing.*
import fl.transitions.TweenEvent;
function firstDisplay():void {
var thisMC:MovieClip = displaySet_ary[nextCount_uint].targetMC;
addChild(thisMC);
thisMC.twn = new Tween(thisMC, "alpha", Strong.easeOut, 0, 1, 10, false);
thisMC.twn.addEventListener(TweenEvent.MOTION_FINISH, twnFinished, false, 0, true);
nextCount_uint++;
}
function twnFinished(e:TweenEvent):void {
e.target.removeListener(TweenEvent.MOTION_FINISH, twnFinished, false);
}
ReferenceError: Error #1069: Property removeListener not found on fl.transitions.Tween and there is no default value.
at overlay_fla::displaySlideshow_mc_8/twnFinished()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.transitions::Tween/set time()
at fl.transitions::Tween/nextFrame()
at fl.transitions::Tween/onEnterFrame()
Child Telling Parent To RemoveEventListener?
I have 2 classes, one being my document class and the other being pulled in as an instance into it.
I need the child to tell the parent to remove an eventListener, but nothing works...does anyone know?
REMOVED_FROM_STAGE, RemoveEventListener(), Contains() And Memory Leaks
Hullo! This is my first post here.
I have been (teaching) scripting for many years with various systems including OOP Flash, and so I am not a beginner. I am using CS3, fwiw.
For my own projects I mostly use classes, which behave exactly as I expect them to, but I get unexpected results when putting code and display objects into the timeline during authoring. I am rather obliged to use scripts and display objects in the timeline because I am teaching ActionScript 3.0 to absolute beginners, and I know from bitter experience that going straight to classes is too great a first step.
In particular, I have various problems understanding AS3's event listener mechanism, especially as it relates to garbage collection with display objects placed on the timeline during authoring.
The problems outlined below mostly do not pertain to display objects added and removed with addChild() and removeChild() respectively.
I am sure this is 'old news' for many of you, but I haven't really been able to find solid, concise information about when (or whether) to use removeEventListener in relation to removeChild() and/or timeline navigation. I'm also having a hard time understanding the 'use weak reference' property, which appears to be relevant here somehow.
My own conclusions are that it is a wise 'rule of thumb' to removeEventListener for every event attached to a movieClip, when the movieClip is taken off stage (for example when navigating to part of the timeline where the clip is not present). That's a big pain in the AS3, especially for beginners, and perhaps worse still for those coming from AS2. Nobody likes cleaning up, least of all beginners and people that never had to clean up before.
It might be 'memory safe' (i.e. leak-free) to leave mouse and key events hooked up (how could we test, anyway?), but stuff like ENTER_FRAME definitely needs to be killed off, or the display object will just keep on keeping on, even when it's no longer 'there'.
It appears to me that the REMOVED_FROM_STAGE event is ideal for this kind of 'cleanup', no? I understand that REMOVED happens just before the object has been removed, whereas REMOVED_FROM_STAGE happens just after.
The docs are not entirely clear to me on the specific subject of display objects placed on the timeline during authoring, which are 'removed' because of timeline navigation, and whether this is supposed to be the same thing as removeChild(). My tests indicate that it is not the same thing at all.
One thing is for sure, display objects placed on the timeline in authoring do indeed get a REMOVED_FROM_STAGE event when the playback head leaves their 'scope' in the timeline.
My questions, then:If I have the 'useWeakReference' parameter as true, when I add an enterframe event listener, is it correct/by design that an object 'removed' from the stage as a result of timeline navigation continues to receive enterframe events? When does such an object get garbage-collected, then? Does the useWeakReference parameter have any meaningful effect at all when adding an enterframe event handler?
Also, what is the 'correct' frame rate to expect when an object has been removed? (Individual timelines can have their own framerate).
It seems to me that these display objects accumulate in RAM, and therefore represent a memory leak - which is what 'useWeakReference' is supposed to prevent, no? This makes me worry about leaving mouse and key events hooked up to no-longer-present movieclips, because every time we return to the timeline scope of those objects, new instances are created.
The docs say that contains() returns "true if the child object is a child of the DisplayObjectContainer or the container itself", but my tests indicate a quirk:
If the object was put on stage, and 'taken off' in a Flash timeline (rather than with addChild/removeChild), the contains() method returns true even AFTER the object is gone. Is this an error of documentation, or my own misunderstanding?
According to the docs, the parent property of a display object is set to null when the object is removed from the stage. (i.e. sometime after REMOVE and sometime before REMOVED_FROM_STAGE), but event.target.parent appears to point to the old value, even in REMOVED_FROM_STAGE events.
I even tried using a timeout of a few seconds, to give Flash a chance to set parent to null (I had to use a class to make this work), but as long as the display object was put on stage in Flash, rather than with addChild(), parent is never set to null after removal, and stage.contains(theNoLongerPresentMovieClip) will continue to return true. This strikes me as downright wrong. Works fine with objects added dynamically, however.
Is it possible to get a list of all the listeners attached to an object? I can't find anything in the docs about it.
To test this, put a movieclip (instance name "m_mc") in frame 1 only of a 2 frame movie. Notice that the parent of the dynamically added/removed object is set to null correctly, but the parent of the object added in authoring remains fixed.
ActionScript Code:
// script for frame 1
// test with object added to stage in authoring (m_mc)
m_mc.addEventListener(Event.ENTER_FRAME, foo, false, 0, true);
m_mc.addEventListener(Event.REMOVED_FROM_STAGE, foo);
// test with dynamically adding and removing a display object:
var m2_mc = new MovieClip();
m2_mc.addEventListener(Event.ENTER_FRAME, foo, false, 0, true);
m2_mc.addEventListener(Event.REMOVED_FROM_STAGE, foo);
trace("**"+stage.contains(m2_mc));
addChild(m2_mc);
trace("**"+stage.contains(m2_mc));
removeChild(m2_mc);
trace("**"+stage.contains(m2_mc));
// leave timeline scope of m_mc
//removeChild(m_mc); comment this back in for 'more correct' behavior
gotoAndStop(2);
function foo(e) {
var et = e.target;
var kids = stage.getChildAt(0)["numChildren"];
var report = "";
report += (et.name + " just got a " + e.type + " event.
");
report += ("Main timeline has " + kids + " children.
");
report += ("Parent of " + et.name + " is " + et.parent + "
");
report += ("stage.contains(" + et.name + ") " + stage.contains(et) + "
");
trace(report);
trace("");
}
Notice also that contains() returns true in both cases in the REMOVED_FROM_STAGE event handler, but in the dynamically added/removed object, contains() functions as advertised thereafter.
This appears to indicate that event.target.parent is NOT null during a REMOVED_FROM_STAGE event, which is contrary to what the docs imply. What then is the difference between REMOVED and REMOVED_FROM_STAGE?
BTW if you removeChild(m_mc) just before going to frame 2, this discrepency disappears. Hmm. Shouldn't Flash just remove the thing properly in the first place?
Thanks in advance for anything which may enlighten me!
RemoveEventListener Wont Remove Event
Code:
private function menuEvents(bool:Boolean, menuItem:Sprite, menuName:String=null) {
if (bool) {
menuItem.addEventListener(MouseEvent.ROLL_OVER, Callback.create(onOver, menuName));
menuItem.addEventListener(MouseEvent.ROLL_OUT, Callback.create(onOut, menuName));
menuItem.addEventListener(MouseEvent.CLICK, Callback.create(onClick, menuName));
trace(menuItem.hasEventListener(MouseEvent.ROLL_OVER) + " bool >>> " + bool);
}else {
menuItem.removeEventListener(MouseEvent.ROLL_OVER, onOver);
menuItem.removeEventListener(MouseEvent.ROLL_OUT, onOut);
menuItem.removeEventListener(MouseEvent.CLICK, onClick);
trace(menuItem.hasEventListener(MouseEvent.ROLL_OVER) + " bool >>> " + bool);
}
}
I am using that function to either add or remove mouse events a particular menu item. But when bool is false, tracing menuItem.hasEventListener always traces true. So apparently this method is not working for remove event listeners. How then?
Calling RemoveEventListener On Dynamic Movie Clips
I'm writing a class that will create an XML-powered slideshow. During the image transition I want to remove the Mouse Click listener on all image thumbnail movie clips so the user cannot interrupt the current transition. I tried calling event.target.removeEventListener but that doesn't seem to do anything. I also realize I need to create a for loop and call removeEventListener on all thumb mc's but am not sure how since all mc's are created dynamically. Any help would be great. Here is my code:
Code:
package com.creativemess.multimedia
{
import flash.display.*;
import flash.events.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import gs.TweenFilterLite;
import gs.easing.*;
import flash.net.*;
public class SlideShow extends MovieClip
{
var dataSource:XML;
var dataList:XMLList;
var dataLoader:URLLoader = new URLLoader();
var imagePath:String;
var imageSmall:String;
var imageLarge:String;
var imageLoaderSmall:Loader;
var imageLoaderLargeOut:Loader = new Loader();
var imageLoaderLargeIn:Loader = new Loader();
var imageDisplaySmall:MovieClip = new MovieClip();
var imageDisplayLarge:MovieClip = new MovieClip();
public function SlideShow (path:String, small:String, large:String)
{
imagePath = path;
imageSmall = small;
imageLarge = large;
dataLoader.load(new URLRequest(imagePath));
dataLoader.addEventListener(Event.COMPLETE, loadImages);
}
private function loadImages (event:Event):void
{
dataSource = XML(event.target.data);
dataList = dataSource.children();
for (var i:int = 0; i < dataList.length(); i++)
{
imageLoaderSmall = new Loader();
imageLoaderSmall.name = dataList[i].attribute(imageLarge);
imageLoaderSmall.load(new URLRequest(dataList[i].attribute(imageSmall)));
imageDisplaySmall = new MovieClip();
imageDisplaySmall.buttonMode = true;
imageDisplaySmall.x = i * 150;
imageDisplaySmall.y = 350;
imageDisplaySmall.addEventListener(MouseEvent.CLICK, tweenLargeImageOut);
addChild(imageDisplaySmall);
imageDisplaySmall.addChild(imageLoaderSmall);
}
imageDisplayLarge.x = 0;
imageDisplayLarge.y = 0;
imageLoaderLargeOut.load(new URLRequest(dataList[0].attribute(imageLarge)));
addChild(imageDisplayLarge);
imageDisplayLarge.addChild(imageLoaderLargeOut);
imageDisplayLarge.addChild(imageLoaderLargeIn);
}
private function tweenLargeImageOut (event:MouseEvent):void
{
event.target.removeEventListener(MouseEvent.CLICK, tweenLargeImageOut);
imageLoaderLargeIn.unload();
TweenFilterLite.to(imageDisplayLarge, .5, {blurFilter:{blurX:30, blurY:30, quality:3}, onComplete:tweenLargeImageIn, onCompleteParams:[event]});
}
private function tweenLargeImageIn (event:MouseEvent):void
{
TweenFilterLite.to(imageDisplayLarge, 1, {blurFilter:{blurX:0, blurY:0, quality:3}, onComplete:displayLargeImage, onCompleteParams:[event]});
imageLoaderLargeIn.load(new URLRequest(event.target.name));
}
private function displayLargeImage (event:MouseEvent):void
{
event.target.addEventListener(MouseEvent.CLICK, tweenLargeImageOut);
imageLoaderLargeOut.unload();
imageLoaderLargeOut.load(new URLRequest(event.target.name));
}
}
}
Calling RemoveEventListener On Dynamic Movie Clips
I'm writing a class that will create an XML-powered slideshow. During the image transition I want to remove the Mouse Click listener on all image thumbnail movie clips so the user cannot interrupt the current transition. I tried calling event.target.removeEventListener but that doesn't seem to do anything. I also realize I need to create a for loop and call removeEventListener on all thumb mc's but am not sure how since all mc's are created dynamically. Any help would be great. Here is my code:
Code:
package com.creativemess.multimedia
{
import flash.display.*;
import flash.events.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import gs.TweenFilterLite;
import gs.easing.*;
import flash.net.*;
public class SlideShow extends MovieClip
{
var dataSource:XML;
var dataList:XMLList;
var dataLoader:URLLoader = new URLLoader();
var imagePath:String;
var imageSmall:String;
var imageLarge:String;
var imageLoaderSmall:Loader;
var imageLoaderLargeOut:Loader = new Loader();
var imageLoaderLargeIn:Loader = new Loader();
var imageDisplaySmall:MovieClip = new MovieClip();
var imageDisplayLarge:MovieClip = new MovieClip();
public function SlideShow (path:String, small:String, large:String)
{
imagePath = path;
imageSmall = small;
imageLarge = large;
dataLoader.load(new URLRequest(imagePath));
dataLoader.addEventListener(Event.COMPLETE, loadImages);
}
private function loadImages (event:Event):void
{
dataSource = XML(event.target.data);
dataList = dataSource.children();
for (var i:int = 0; i < dataList.length(); i++)
{
imageLoaderSmall = new Loader();
imageLoaderSmall.name = dataList[i].attribute(imageLarge);
imageLoaderSmall.load(new URLRequest(dataList[i].attribute(imageSmall)));
imageDisplaySmall = new MovieClip();
imageDisplaySmall.buttonMode = true;
imageDisplaySmall.x = i * 150;
imageDisplaySmall.y = 350;
imageDisplaySmall.addEventListener(MouseEvent.CLICK, tweenLargeImageOut);
addChild(imageDisplaySmall);
imageDisplaySmall.addChild(imageLoaderSmall);
}
imageDisplayLarge.x = 0;
imageDisplayLarge.y = 0;
imageLoaderLargeOut.load(new URLRequest(dataList[0].attribute(imageLarge)));
addChild(imageDisplayLarge);
imageDisplayLarge.addChild(imageLoaderLargeOut);
imageDisplayLarge.addChild(imageLoaderLargeIn);
}
private function tweenLargeImageOut (event:MouseEvent):void
{
event.target.removeEventListener(MouseEvent.CLICK, tweenLargeImageOut);
imageLoaderLargeIn.unload();
TweenFilterLite.to(imageDisplayLarge, .5, {blurFilter:{blurX:30, blurY:30, quality:3}, onComplete:tweenLargeImageIn, onCompleteParams:[event]});
}
private function tweenLargeImageIn (event:MouseEvent):void
{
TweenFilterLite.to(imageDisplayLarge, 1, {blurFilter:{blurX:0, blurY:0, quality:3}, onComplete:displayLargeImage, onCompleteParams:[event]});
imageLoaderLargeIn.load(new URLRequest(event.target.name));
}
private function displayLargeImage (event:MouseEvent):void
{
event.target.addEventListener(MouseEvent.CLICK, tweenLargeImageOut);
imageLoaderLargeOut.unload();
imageLoaderLargeOut.load(new URLRequest(event.target.name));
}
}
}
AS3... Stopping The Download Of An External File (removeEventListener?)
On my stage, I have three buttons each of which is used to load an external swf file onto the stage (via an emtpy movie clip). I have an addEventListener that calls a function that adds the swf file to the stage using the addChild method. This function is called on Event.COMPLETE (when the external movie finishes downloading)
When testing the master file, I'm using Simulate Download so that I can monitor the download progress (I have a preloader on the stage that displays percent loaded, etc). So let's say I click on the third button which begins loading movieC. I then change my mind halfway through the download process of movieC and decide I want to see movieA. So I click on the first button. But what ends up happening is that both movies are still going through the download process (though the preloader is accurately only reporting information about the newest movie that's downloading). The reason why I know that movieC is still downloading is that it will show up on my stage while movieA is still downloading. When movieA finally finishes downloading and shows up on the stage, then movieC will go away. (As a side note: how movieC gets removed once movieA shows up is beyond me because I'm not using removeChild and I thought that without removing the child, external movies will just stack right on top of one another. ??)
I am not sure how to kill the download/display of the movie that's loading from when I clicked on the third button (movieC). I have tried using removeEventListener but it's not working. I suspect that you can't remove a listener while it's monitoring something. Perhaps it can only be removed once the event is complete? If that's the case, how in the heck do I stop another movie from downloading/displaying should I change my mind and click another button to view a different movie?
I hope this all makes sense. I'm so tired after hours of working on this file that I can't tell the ceiling from the floor at this point. Oh, and my hair fell out 2 hours ago. Or maybe I pulled it out.
Any help would be appreciated.
Brenda
Function In A Function In A Function, A Scope Problem
Is this basic or what.. I have a nested functions, and I'm having a hell of a time getting all my variable through.
ActionScript Code:
var canyouseemee;
public function move()
{
for(var i:Number = 0; i < blah; i++)
{
zing, and then zang
if (zing==0)
{
guts
}
if (zang ==0)
{
something else
}
}
}
Now, I had always thought that since var canyouseemee is declared at the topmost layer, that I'd be able to see it from anywhere below it. Well, it turns out that I can only see it from within the move()function, and not anything below it. is this normal? I thought you couldn't see a local variable of a lower (deeper) function, but could see higher (shallower) variables...
Call A Function In A Duplicated Movie Clip Form Another Function : (
i have a movie clip on my root name "pl".
on command, it duplicates with instance name as "y0","y1", etc.
here is the method :
function callPL(transmit,receive,addy,level) {
var newName = "y"+_root.x;
duplicateMovieClip("_root.pl",newName,101);
_root[newName]._x = 400;
_root[newName]._y = 400;
_root.[newName].start(transmit,receive,addy,level); //look here
}
there i attempt to call a function of the newly duplicated clip call "start()".
Start() function is written on the first frame of the movieclip like this :
function start(a,b,address,level) {
a.sendAndLoad(address,b,"Post");
this.path = b;
b.onLoad=function(success) {
gotoAndPlay("start");
}
}
however it seems like the function callPL() could not invoke function start() of the new movieClip.I have no idea how is it so.
Even when i trigger it with a onLoad handler it still doesnt work
pls shed some light.
|