Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Event Listener From Other Classes



i am dispatching a event from a movieclip class.my document class could hear it if i do this:
Code:
addEventListener("onJump", jumpReceived, true);
apprently, i must set the last parameter of capture to true. otherwise, i won't get the dispatched event. i am not sure why though.then now my problem comes when i am trying to listen to this event from one of the other movieclip classes. i did the same thing that i have done in my document class to listen to the event with the same callback function, but it doesn't seem to detect anything.how could i listen to it from other movieclip classes?thanks.



KirupaForum > Flash > ActionScript 3.0
Posted on: 08-05-2007, 03:56 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Setting Up An Event Listener To Listen For An Event Inside Of Another Movieclip.
I'm trying to set up an event listener on the stage that will listen for a mouseEvent.CLICK on a certain button inside a movieclip on the stage, but i cant seem to figure out how to target that specific button. Any help would be greatly appreciated.

Passing Parameters From Event Listener To Event Handler
Hi Chaps,

First of all, apologies as I know this question has been asked before, but I have spent the last twenty minutes reading this thread and still can't seem to figure out how to apply it to my situation - probably because I'm thick!

I have a number of objects which need to be rotated according to different parameters. I have a function which takes those parameters, then uses the tween class to handle the rotation. I'm then using the tweenEvent class to check for when the motion is complete. Then, I need access to those same parameters in the complete handler to do further operations. The problem I have is that the tween event class doesn't allow me to pass the parameters along to the cpmpleteHandler, so I'm stuck getting my parameters from the first function to the second function:


Code:
function rotate(parameters){

rotationTween = new Tween(object,parameter1,parameter2,........);

rotationTween.addEventListener(TweenEvent.MOTION_FINISH,completeHandler);

}

function completeHandler(e:TweenEvent){

//need access to the paremeters passed into the first function here!!

}
From reading the thread mentioned above, I have a feeling I may need a custom class to do this - please don't laugh but I've never written (or had the need to) write my own class before, so I really wouldn't know what to do. Any help greatly appreciated, but an actual code snippet which demonstrates this would be even better!

Ric.

Event Listener Mouse Event Click - Obstructions
This is an oversimplification of my problem.

I have an event listener on a sprite.
I then have portions of this sprite covered with other sprites or moveclips.

If I click a movieclip, it blocks my eventlistener on the sprite underneath it.

Is it possible to listen to the even click 'through' a movieclip. I dont want interaction with them, but I dont want them as bitmap data onto the base sprite either...

Mouse Event Add Event Listener?
sorry, could not think of a better title!
anyway,
I downloaded a class that perfectly works for me,
it's basically a cube that rotates depending on mouse movement,
the way it does it is with the following line:

spBoard.addEventListener(MouseEvent.MOUSE_MOVE,boa rdMove);


what this does is, whenever the mouse moves the cube moves
the boardMove function does the movement based on the mouse's current position

but what i want to do is the keep the cube moving, if the mouse is on its left, it keeps rotating left, and on its rght, keep rotating right...and preferably to have the speed increase/decrease depending on how far/close mouse is to the center of the cube

any suggestions?
firstly is there an event listener that keeps calling the function just for the mouse 'being there' ? i tried rollover, didn't work

or maybe the boardMove function should be modified? i have no idea how though, totally new to AS3, here's the boardMove function for refrence:


ActionScript Code:
private function boardMove(e:MouseEvent):void {
        
                var locX:Number=prevX;
               
               
       
                if(doRotate){
               
               
                prevX=spBoard.mouseX;
                               
               
               
               
                               
                curTheta+=(prevX-locX);
                                   
               
               
                renderView(curTheta);
               
                e.updateAfterEvent();
               
                }
    }

[F8] External Classes & Listener Help..
ok.. I need some help on this.... my OOP stinks...

and Im having trouble getting this to work.

I am using the OnScreenKeyboard from here:

http://www.dncompute.com/blog/2006/0...-keyboard.html

As far as getting the keyboard to show-up and 'work'.. that is working...

but Im trying to add a listener to the text field to trigger a function on the onChanged() event...

summary of how the KeyBoard works:

1.) library has several movieClips in it.. they are linked to the external.as class that matches it.

2.) the clip is dragged on stage from library... once project loads it uses the placement/position of the keyboard display text field in this clip to attach the keyboard (under the text field a little)

now in the class files I have found where to edit it where I trace out some text on each Press/Click... but I dont seem to know ow to add my listener.

1.) do I add it (some how) to the external.as class?
2.) or do I keep it in the .fla like I have been trying?

or is it a combination of the two possibly? registering a callback function for the onChanged() event that resides in the .fla?




this is the code I have been trying to use to add my listener to the textField that is inside this movieClip linked to the external class(es)


PHP Code:



//create keyboard textField listener
var txtListener:Object = new Object();
txtListener.onChanged = function(textfield_txt:TextField):Void  {
    trace("text changed");
    var chosenLetter:String = textfield_txt.text;
    //var chosenLetter:String = tLetter.text;
    returnedArray = filterArray(chosenLetter);
    for (var i:Number = 0; i < returnedArray.length; i++) {
        trace(returnedArray[i].itemName);
    }
    removeMovieClip(menuContainer.linkContainer)();
    createSortedList();
};
//add listene to textField
searchField_mc.display_txt.addListener(txtListener);




searchField_mc is the name of the clip that houses the disyplay text field and where the keyboard get attached into.. display_txt is the field Im trying to add my listener to.

NOW.....if I make a new movieClip (generic one) with a textField in it.... and try to use that one to add my listener too... it works... just NOT the textField that is iside this clip that is linked to the external.as class

hope Im making sense external classes, scope and listeners isnt really my strong point

if anyone cant help me sort this Id appreciate it..

thanks

Event Listener?
Hi,

I have an flv playing in my media display, but when the flv ends I want to "go to and play" a specific frame. The media diplay is a movie with additional graphics and a media controller attached to it. I am working in "screens" mode, does this pose any problems like having to tell it which frame # in which screen?

Event Listener?
Hello everyone,

I'm trying to learn Flash from a book and I've been getting on OK but I want to do something that my book doesn't cover.

I've got an invisible button the same size and shape and in the same position as a square dynamic text field. When the button is pressed, a movie-clip (about twice the size of the button/text field) plays around the same position. The movie-clip has 39 frames but I've set it to stop on frame 20. On frame 20, the user is presented with a set of buttons numbered 1 to 9 (and a delete button labelled 'X') arranged in a dial around the dynamic text field (and, of course, the invisible button). If the user clicks one of the numbered buttons, that number is placed in the dynamic text field, and the movie-clip completes. The movie-clip also completes if the user clicks the original invisible button a second time (this leaves the dynamic text field unchanged.) The general effect is that the dial of numbered buttons grows from the centre of the text field and then shrinks back into it when a number is chosen.

All this works fine so far, however I have several invisible buttons (with associated dynamic text fields and movie-clips) identical to the one above, and I only want one movie-clip to be active at any one time. What I'm hoping to do is to arrange things so that the movie-clip will complete if the mouse-pointer moves outside of the movie-clip area.

I imagine I'd need some kind of event listener to do that and possibly something to do with _xmouse and _ymouse, but I haven't been able to work out how to do it.

Any help you can give me would be much appreciated.

Cheers,

Jeff

Event Listener?
Hello everyone,

I'm trying to learn Flash from a book and I've been getting on OK but I want to do something that my book doesn't cover.

I've got an invisible button the same size and shape and in the same position as a square dynamic text field. When the button is pressed, a movie-clip (about twice the size of the button/text field) plays around the same position. The movie-clip has 39 frames but I've set it to stop on frame 20. On frame 20, the user is presented with a set of buttons numbered 1 to 9 (and a delete button labelled 'X') arranged in a dial around the dynamic text field (and, of course, the invisible button). If the user clicks one of the numbered buttons, that number is placed in the dynamic text field, and the movie-clip completes. The movie-clip also completes if the user clicks the original invisible button a second time (this leaves the dynamic text field unchanged.) The general effect is that the dial of numbered buttons grows from the centre of the text field and then shrinks back into it when a number is chosen.

All this works fine so far, however I have several invisible buttons (with associated dynamic text fields and movie-clips) identical to the one above, and I only want one movie-clip to be active at any one time. What I'm hoping to do is to arrange things so that the movie-clip will complete if the mouse-pointer moves outside of the movie-clip area.

I imagine I'd need some kind of event listener to do that and possibly something to do with _xmouse and _ymouse, but I haven't been able to work out how to do it.

Any help you can give me would be much appreciated.

Cheers,

Jeff

Key Event Listener
Hi,

i'm doing a game using the keyboard as controls.

I upload it onto the web and not all keys are working. Is it because of the below?


Quote:




A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.




But if that is the case, why not all keys but only some are not working?

The arrow keys are working fine but the letters are not?

Anyone, any idea?

Event Listener...
I have a client that would like his video to auto play on initiation(frame 6) but as soon as the video is over gotoAndPlay(5) which would give the user the option to play the video again or select other various options(which means the video needs to be gone).

I was trying to use a listener to determine when the FLV is finished to navigate back to another frame. I believe I'm missing something here... Here is my script in frame 6

stop();
var listenerObject:Object = new Object();
listenerObject.stopped = function(eventObject:Object):Void {
gotoAndPlay(5);
};
my_FLVplybk.addEventListener("stopped", listenerObject);

Event Listener
Hi!

Is there any way of getting all the events triggered by an SWF? We need to get the name of the component (MovieClip, Button, Input Text...) which has received the event.

Any clue?

Best

Event Listener Help
What is the most efficient way of detecting when a movie clip has reached a certain frame?

The only method i know atm is adding a onEnterFrame listener and then checking every frame, but i doubt this is really efficient.

Event Listener Help
Hi, I am trying to get an event listener to work. It is just a mouseclick that traces "Click". Right now it only works when I click on the movieclip. I want it to work when I click anywhere on the stage.

Here is my code:
Main:

Code:
package src{
import src.Character;
import flash.display.MovieClip;
public class Main extends MovieClip {
public var char:Char;

public function Main() {
char = new Char();
char.x = char.y = 50;
stage.addChild(char);
}
}
}
Character:

Code:
package src{
import flash.display.MovieClip;
import flash.events.*;
public class Character extends MovieClip {

public function Character() {
this.gotoAndStop(1);
this.addEventListener(MouseEvent.CLICK, Click);
}
function Click(e:MouseEvent) {
trace("Click");
}
}
}
Please help.

Some Help Please With An Event Listener
Hi guys,

How can I create an event listener that detects when I resize
a text field dynamically?


ActionScript Code:
inputField.addEventListener(Event.CHANGE,onResizeField);

function onResizeField(event:Event):void{
   
    trace("has been resized");
}

The above doesn't work and I have tried already Event.RESIZE
without access.

Any ideas?

Thanks a lot

Event Listener
Hey there. I am, to say the least, new at writing code. Here is my problem. I currently have a video that plays thru my instance called clydeplayer as seen in the following code:

on (rollOver) {
this.gotoAndPlay("s1");
}
on (releaseOutside, rollOut) {
this.gotoAndPlay("s2");
}
on (release)
{
_root.myMC.clydeplayer.contentPath = "http://www.clydemedia.com/Video_for_site/GAN111.flv"
}


What I would like to happen after this video clip "GAN111.flv" plays is to have another video, located in the same spot, start playing automatically.

like I said, I really have very little knowledge on how to do this so any help would be great. thanks!

Event Listener?
Can anyone help me....

I am making a flash banner and it goes like this...

I have the first moveicip playing on the main timelne and then buttons that contrtol the movie loadd in... you can click on button 1 and it will take you to frame 122 where the second movie clip is and clilck on button 2 to go to frame 123 which is the third movieclip and button three restarts the first movieclip by going back to frame 1....

however, there are two things I am trying to do... I want to figure out the code that will make the movie (on main timeline) play frame 122 then frame 123... if no buttons are pressed and reloop.... but go to a specific movieclip when pressed...

and also in my movies... the buttons are not going the the main timeline.... they're playing frame 122 anda frame 123 of the current timeline (i loaded the second and third moviecip onto the timeline on frames 122 and 123 respectively)....

where do i put the code and does anyone have any ideas... I know i may have to use an event listener i think to control the timeline.. i dunno.. i'm pretty new at this.. a bit stuck...

jan

Event Listener
Hi Guys,

How can i create custom event in AS 3.0.

Thanks
MS

Event Listener
I have a script that creates falling snow. I want to be able to control the amount of snow from a slidebar how would I do this? In this case "snow_per_second" controls how much it will snow.
The current script: (sorry it's a bit long)








Attach Code

var speed:Number = 3;
var total_snow:Number = 20;
var snow_per_second:Number = 4
var hit_target:MovieClip = myObject
//
var holderSnow:Sprite = new Sprite();
var target_shake:Boolean = false;
//
addChild(holderSnow);
//
hit_target.mainX=hit_target.x;
hit_target.mainY=hit_target.y;
//
function createSnow() {
var snow:MovieClip = new MovieClip();
snow.graphics.beginFill(0xFFFFFF);
snow.graphics.drawCircle(0,0,Math.random()*3);
reset(snow);
addBlur(snow);
snow.addEventListener(Event.ENTER_FRAME,fall);
holderSnow.addChild(snow);
}
function reset(s:MovieClip) {
s.hit=s.shake=false;
s.y=0;
s.x=Math.random()*970;
s.xspeed=Math.random()*speed-(speed/2);
s.yspeed=Math.random()*speed+1;
}
function init(e:Event) {
for(var i=0; i<snow_per_second; i++) {
createSnow();
}
snow_id++;
if(snow_id>total_snow) {
removeEventListener(Event.ENTER_FRAME,init);
}
}
function addBlur(s:MovieClip) {
var blurX:Number = Math.random()*2+3;
var blurY:Number = Math.random()*2+3;
var filter:BitmapFilter = new BlurFilter(blurX, blurY, BitmapFilterQuality.LOW);
var myFilters:Array = new Array();
myFilters.push(filter);
s.filters = myFilters;
}
function fall(e:Event) {
if (!e.target.hit) {
e.target.x+=e.target.xspeed;
e.target.y+=e.target.yspeed;
if (e.target.y>600) {
reset(MovieClip(e.target));
}
if(!e.target.shake) {
if (hit_target.hitTestPoint(e.target.x,e.target.y,true)) {
e.target.hit=true;
}
}
}else{
if(target_shake) {
e.target.hit=false
e.target.shake=true;
}
}
}
function shake_int(e:TimerEvent) {
hit_target.x=hit_target.mainX+Math.random()*5-2.5;
hit_target.y=hit_target.mainY+Math.random()*5-2.5;
}

target_shake=true;

//
hit_target.addEventListener(MouseEvent.CLICK,shake_start);
function shake_start(e:Event) {
target_shake=true;
//shake_timer.reset();
//shake_timer.start();
}
//
var snow_id:int = 0
addEventListener(Event.ENTER_FRAME,init);

Event Listener, Help
If ten mc's are going to have the same MOUSE_DOWN event, how can I, inside the mouseDown-function, know which mc it is? Like;

ActionScript Code:
for(var i=0;i<10;i++) {this["mc"+i].addEventListener(MouseEvent.MOUSE_DOWN, press);}function press(e:Event) { // lol? Could it be mc0 or mc2 or mc9? wtf...}

External COM Event Listener
ok heres the deal i want to know if this is possible.

using CE.NET for pocket pc.. which only supports flash player 6.. can you build a COM event listener that waits for an action from the server. then envokes an action within flash and also sends a result out of flash back to the server.

I have found a few examples of listeners within flash but they are dependent on actions within flash. I need to build a flash movie that sits static until a result is sent by the server.. not a user actively clicking on a button or anything.

can anyone point me to something like this that has been built? and what i need to study up on to make this work..

Thanks,
Kirk

Datagrid And Event-listener
Ive got a DataGrid, and Id like to get the value from one of the cells as soon as it has been changed (its editable).

Problem is, I only know how to get ahold of the row-index, and the column-index, but not the data inside the cell.

Anybody knows?

code:
myDataGridListener = new Object();
myDataGridListener.cellEdit = function(event){
var colIndex = event.columnIndex; // gets columnnr
var rowIndex = event.itemIndex; // gets rownr

var myCellsValue = event.?????? // How do I get the value inside this cell?
}
myDataGrid.addEventListener("cellEdit", myDataGridListener);

[F8] TextInput Event Listener
I’m in Flash 8 and working with the TextInput component.

My question is about setting up an event listener. I would like to fire off a few methods when the user clicks out of the TextInput with there mouse, or by tabbing out of the field.

Does anybody know of a good way to do this?
Is there a way to setup an unfocus event?
Thanks!


PHP Code:



var my_ti:mx.controls.TextInput;
var tiListener:Object = new Object();
tiListener.change = function(evt_obj:Object) {
trace("trigger methods”);
};
my_ti.addEventListener("??field_unfocus??", tiListener);

Event Listener Not Listening
I have a component that dispatches an event like this:
dispatchEvent( new Event( "fooChanged" ) );

In my Application
<mx:Application ... creationComplete="init()">
<mx:Script>
<![CDATA[
private function init() : void {
addEventListener( "fooChanged", handleChange );
}

public function handleChange (event:Event) : void {
....
}
]]>
</mx:Script>

The handleChange function never gets fired. Is there some big important piece I am missing?
Thanks

Event Listener Issues
Howdy,

I'm making a game with multiple characters. You move them by clicking on them, then clicking where you want them to move. Everything works great, except for when one character is traveling, and the user changes his or her mind and clicks somewhere else before the character reaches their destination. For some reason, my code will not remove the old event listener before assigning the new one.


heres the code:


stage.addEventListener(MouseEvent.CLICK, moveStarter);

function moveStarter(e:MouseEvent){
var xx = root.mouseX;
var yy = root.mouseY;

frank = personcontainer.getChildByName(whichCharacter);

///frank is the name of the variable i use tell the program which character is selected. the variable whichCharacter is defined elsewhere.


////in the code below, the hasEventListener command works, returning "true"
only when the character is moving. But the removeEventListener command does nothing.

if (frank.hasEventListener(Event.ENTER_FRAME)){
frank.removeEventListener(Event.EnterFrame, frankmover)
}else{
trace("not currently moving");
}

frank.addEventListener(Event.ENTER_FRAME, frankmover);

function frankmover(e:Event){
////there is code here that moves the character to the point xx, yy then removes the eventListener. It all works fine.

}

}



If anyone has any ideas, please let me know before i get too angry and dropkick my computer.

thanks so much!

-kenny

Generic Event Listener
Using the Loader class, I'm loading a SWF on to the stage. In AS 2.0, I would have a single event listener call a specific function based on the event triggered. In AS 3.0, can I do the same thing. Because I am using the Loader constructor, I only want the one listener to call 3 possible function based on that event.

Seems to makes sense to me. I would use the following:


Code:
screen_mc.addListener(screen_listener);


The screen_listener would be declared as an Object previously.

Event Listener - First Time Ever
Hi, I'm trying to add an event listener. So that when a button is pushed it will skip a AS frame in another MC.

Graphically what it's supposed to be is a plane_mc is flying and when the button is pushed the loop frame gotAndPlay(1); is skipped and the plane looks as if its landing.


Code:
var obj = new Object();

obj.click = function(evt) {

_root.carribean_mc.onRelease = function() {
_root.Plane_mc.Plane_mc2.skip(108);

};
};

_root.carribean_mc.addEventListener("click",obj);
I'm not sure about this. Its my first time trying something like this

Event Listener Question
I have my Main Document Class and it registers an event listener for an instance of another class, we'll call it CommMgr. CommMgr dispatches 2"Event.COMPLETE" events and I want the Main class to process each of those differently, so for example (pseudo-code):

commMgr.listener(event, doSomethingForFirstEvent)
commMgr.listener(event, doSomethingForSecondEvent)

how would I differentiate between which event is being fired (1st or 2nd?) because they are both the same type of event (Event.COMPLETE in this case)? plz advise! thx!

Listener Event Burp
Well, I have this strange problem...I won't ask people to look at my code (unless they think it would help) I'm just wondering if anyone has seen this issue:

http://www.geocities.com/dr_baboom/Pong.swf

after you click the start, all of the key listeners do not kick in until I click the screen again.

Any ideas of what could cause that?

[F8] Is An Event Listener Required?
I am relatively new to Flash8, have no prior programming experience and this is my first plunge. Performance is inconsistant when using the following conditional statement to direct a movie clip instance to the appropriate frame label:

lowerback_mc.onRollOver = function (){
if (speedo_mc.needle_mc._rotation == -45) {
speedo_mc.gotoAndPlay("135d180");
} else if (speedo_mc.needle_mc._rotation == -90) {
speedo_mc.gotoAndPlay("90d180");
}
}

My guess is that an event listener needs to be implemented in order to track the current needle_mc rotation. If so, how? If not, any suggestions?

Parameters With Listener Event
I may just be looking wrong, but I can't find a very good method for passing parameters into a function that is being used for an event...I would like to accomplish this:


PHP Code:




public function loadTilePixelData(PixData:String, TilesWide:int, TilesHigh:int, DataCellWidth:Number, DataCellHeight:Number):void {
    loadedPicture.load(new URLRequest(PixData));
    loadedPicture.addEventListener(Event.COMPLETE, pictureLoadComplete(TilesWide, TilesHigh, DataCellWidth, DataCellHeight));
}







hopefully without having to assign a bunch of random vars to get the data from one function to the next via event.

Any recommendations for this one?

Can I Use An Object As An Event Listener?
I have a mouse (rat_mc) and an elephant (dumbo_mc). The rat_mc is a draggable object and the elephant is sitting on the stage. Can I make it so that when a user drags the rat over the elephant, the elephant does something (jump, run away... etc).

Any ideas? What should the script look like to do that?

I'm a noob obviously.

Thanks!

Can I Use An Object As An Event Listener?
I have a mouse (rat_mc) and an elephant (dumbo_mc). The rat_mc is a draggable object and the elephant is sitting on the stage. Can I make it so that when a user drags the rat over the elephant, the elephant does something (jump, run away... etc).

Any ideas? What should the script look like to do that?

I'm a noob obviously.

Thanks!

Event Listener Mouseclick
Is it possible to pass a variable to the eventListener?

The current As2 code is like this.
aButton.onPress=function(){
changeColor(this);
}

function changeColor(mc:MovieClip){
mc.alphaTo(50,.5,"linear");
}

The AS 3 is using the event listener, but is there a way to pass mc as a variable to the function during the function call??


aButton.addEventListener(MouseEvent.CLICK, changeColor);// anyway to pass the aButton reference to the function call?
function changeColor(event:MouseEvent, mc:MovieClip):void {
mc.alphaTo(50,.5,"linear");
}

Thanks

Felix

Maybe An Event Listener Question AS2
I've looked topics here and didn't find what any. So here's my problem. Hope someone can help. Basically, I have an index page that has navigation like below and an intro animation. I am using attachMovie and mcTween for these.

About
Portfolio
Music
Blog

Problem:
The Intro has its own animation which is in the actual swf(not external)
When the user clicks on the "about" link , I have a function that makes the intro animation do a transition to 0% of the alpha and an external swf is loaded in its place. Now, when the page loads, if the user clicks the navigation before the intro animation starts, the intro animation gets all wonky. I'm trying to find the best approach to this. Should I do a listener or just deactivate the nav until the animation is done. Not sure how to do a listener or deactivate. Any help would be great! Hope that wasn't confusing!

[as2]Event Listener In A Class... HELP
I can't seem to figure out how to use an event listener in an AS2 class. Someone please help me. I feel like a moron. Here's my code, and please excuse if it's completely wrong, I'm not very good at classes yet:


PHP Code:



import flash.filters.BlurFilter;import flash.ui.Mouse.*;import flash.geom.Point.*;class ProximityBlur extends MovieClip{        var targetX:Number;    var targetY:Number;    var distance:Number;        var myStage:MovieClip; //stage        var bf:BlurFilter;        var mLis:Object = new Object();        var targetClip:MovieClip;        function ProximityBlur(myClip:MovieClip, movieHome:MovieClip)    {        targetClip = myClip;        targetX = targetClip._x;        targetY = targetClip._y;                myStage = movieHome;        bf = new BlurFilter(0,0,3);//I've used multiple methods trying to get this to work... thus the reason you see both of the lines below...                myStage.onMouseMove = blurClip(targetClip);                Mouse.addListener(mLis);    }        mLis.onMouseMove = function()//ERROR on this line! "This statement is not permitted in a class definition"    {        distance = Math.sqrt(((targetX - _xmouse)*(targetX - _xmouse)) + ((targetY - _ymouse)*(targetY - _ymouse)))        trace(distance);    }        function blurClip(myMC:MovieClip)    {        distance = Math.sqrt(((targetX - _xmouse)*(targetX - _xmouse)) + ((targetY - _ymouse)*(targetY - _ymouse)))        trace(distance);        if(distance <= 100)        {            bf.blurX = distance/10;            bf.blurY = distance/10;            myMC.filters = [bf];        }    }}




Any help would be very much appreciated. I just don't understand why I can't use a mouse event in an AS2 class. Oh, I forgot to mention that I got this working perfectly just coding it on the timeline, but I want to make it reusable and I can't seem to get how to turn it into a class.

Event Listener Question
If i have something like this where an object has an event listener on it, but then you removeChild the object and set it to null, does the event listener still exist?

randomObject.addEventListener(MouseEvent.CLICK, reaction);
removeChild(randomObject);
randomObject = null;

//does randomObject's event listener still exist?

Event Listener Problem
Hi-

I have an flv playing through a .swf file, After the flv finishes I would like a static image to appear. I thought this would work:


Code:
hands._visible = false;

listenerObject.complete = function(eventObject:Object):Void {
hands._visible = true;
};
myPlayer.addEventListener("complete", listenerObject);
"hands" being the image, "myPlayer" being the video - But i must be doing something wrong. The video plays, no problem - but the static image never reappears.

thanks in advance

Re-use Event Listener Object?
Hi Everybody,

I have about 10 buttons on my stage.
I don't want to write 10 addEventListener objects, but write just 1 OO-function like:


Code:
thisButtonListener = new Object();
thisButtonListener.click = function() {
// my actions...
}
thisButton.addEventListener ("click", thisButtonListener);
So, actually, I want to re-use this object for all my 10 buttons...
IS this possible? And if so, can anyone show me a code example?

Regards,
Vic

Event Listener Coding...
Hey there,
It's just more to know how you guys are developing.
I mean with the EventDispatcher class it becomes really easy to use only the EventDispatcher way to dialog between instance, instead of eg, if you have a composition in a class and do yourotherobjectinstance.themethod();

So just wondering what is the best way.
Always using EventDispatcher (I can't see drawbacks). If not if you could explain me why...

Cheers...

Multi - Event Listener;
Hi,

Is there any way to add an Event listener which listens to any event that a class dispatches rather than a specific one?

I am trying to work out a generic way of getting events out of one swf into the swf that loaded it. The main swf loads a variety of different swfs, and needs a set way of listening to their events, so I thought I could use a standardised function in each swf that is loaded which catches all events broadcasted by any classes instanciated and which can be subscribed to by a manager class in the main swf.

Delegate/event Listener Help
I'm looking for help resolving a scoping issue whenever I use the onMotionFinished function of a tween. Is there a way to use delegate to increase the scope of the onMotionFinished function to my entire manager class?

Event.ID3 Listener Runs Twice?
I'm trying to get the id3 tags of a song and when i load the sound the id3 triggers twice.Here is the code

Code:

//an mp3 file is send to the function
private function addMusicToPlaylist(file:File):void{
var url:String = file.url;
var mp3URLRequest:URLRequest = new URLRequest(url);
var music:Sound = new Sound();
music.load(mp3URLRequest);
music.addEventListener(Event.ID3,sendID3);
}

private function sendID3(event:Event):void{
trace(event.bubbles);
var title:String = event.target.id3.songName;
var artist:String = event.target.id3.artist;
var url:String = event.target.url;
var album:String = event.target.id3.album;
var xml:XML = <mp3>
<title>{title}</title>
<artist>{artist}</artist>
<url>{url}</url>
<album>{album}</album>
</mp3>
parentDocument.parentDocument._xmlData.appendChild(xml);
//trace(parentDocument.parentDocument._xmlData);

Event Listener Target Is Not What I Ask It To Be
It it only me...

I have a project where menu is being buildt from a xml file. Each node corespnds to a button that expands when you mouse over. My problem is that if I create theis button as a sprite the event listener target is a sprite, in I append a TextField to this sprite the event listener target becomes the textfield.

example:
var txt = new TextField();
var container = new Sprite();
container.graphics.drawRect( 0,0, 100, 20);
container.addEventListener( MouseEvent.MOUSE_OVER, menuIsAccessed);
someStage.appendChild( container )

This would give me container as the target of the MouseEvent, if however I add the textfield to the display list: container.appendChild(txt) the event target becomes the textfield.

Is there some hierarchy in the display list that I do not know about or am I completely missing some basics?

Anyway, thanks to all you brilliant minds out there, I have been reading this forum for the past two months and learned incredible much from all of you.

Thanks in advance

Event Listener Or Return Or What?
I'm setting up a class that compares strings.

It has a method where you pass 2 strings into it:

myClass.compareStrings(inputString:String,original String:String);

It goes through a complex sequence of comaprisons and there can be 5 possible outcomes.

I've set up variables like this:

ActionScript Code:
public static const BLACK:String = "black"; // whole strings match
        public static const GREEN:String = "green"; // substring matches
        public static const SUBGREEN:String = "subgreen"; // last character matches
        public static const AMBER:String = "amber"; // last character matches but wrong position
        public static const RED:String = "red"; // last character doesn't match

but I'm not sure that event listeners are the right way to go about it.

Could I use return in some way? I've never used return in this way before so please be gentle with me!

Event Listener Question
So I created a close btn within a movie clip -

popInfo.closeBtn is the path, when I create the event listener do I need to keep the same path to call the event listener - thats what I did and it doesnt seem to be working.

Here it my code:

Code:
// event listeners

seattleBtn.addEventListener(MouseEvent.CLICK, onClickSEA);
closeBtn.addEventListener(MouseEvent.CLICK, onClickRemove);


// functions

function onClickSEA(event:MouseEvent):void
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);

}


function onClickRemove(event:MouseEvent):void
{
removeChild(popInfo);
}


// set button mode here
seattleBtn.buttonMode = true;
closeBtn.buttonMode = true;
Im adding popInfo with one click and trying to remove it with another. But its not working. Please help!

Event Listener Problem
this is the code in my document class:

ActionScript Code:
for each(var guide:Guide in guides){
    siteSprite.addChild(guide);
    guide.addEventListener(MouseEvent.MOUSE_OVER, guideMouseOverHandler);
}

private function guideMouseOverHandler(evt:MouseEvent):void{
    var guide:Guide = Guide(evt.target);
}

when i roll over the object with my mouse i get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Sprite@21a27089 to Classes.Guide.
at Index/::guideMouseOverHandler()

so i have an array with guide objects, and on each one i hang the same handler, but how can i get the original guide-object again?

Buttons Event Listener
I have a sprite in which i placed in ButtonMode. On top of this sprite, I add a TextField to act as a label via sprite.addChild(textfield); Now, whenever I hover over my button it will fire the appropriate event listeners like MOUSE_OVER. The problem is, if I hover over the text field, it WILL NOT fire MOUSE_OVER on the sprite! How do I handle this? I have an event listener on the button for pretty much every mouse event: MOUSE_DOWN, MOUSE_OVER, etc, but they do not fire if I hover over the button's text field! Please help!

Help With Custom Event Listener
I'm having some trouble with a custom event listener.
The listener fires as far as I'm aware of. The problem is that I have my main document registered to listen for the event and It dosn't seem to be catching it?

On my main document as soon as it starts I make a instance of a loader class. This class dosnt do anything yet except dispatch my custom Event
Audio Loader Class

ActionScript Code:
package {
    import flash.errors.*;
    import flash.net.*;
    import flash.events.*;
    import flash.display.*;
    public class audioLoader extends MovieClip {


        public var workpath:String="loopMaster";
        public var mc:MovieClip=new MovieClip  ;

        public function audioLoader() {
            onComplete()
        }
        public function onComplete() {
            dispatchEvent(new loadEvent(loadEvent.LOAD_COMPLETE));
        }
    }
}

Here is the code for my event


ActionScript Code:
package {
    import flash.events.*;

    public class loadEvent extends Event {

        public static  const LOAD_COMPLETE:String="complete";

        public function loadEvent(type:String,bubbles:Boolean=true,cancelable:Boolean=false) {
            super(type,bubbles,cancelable);
            trace("event test :" + type);
        }
        public override  function clone():Event {
            return new loadEvent(type);
        }
    }
}

now here is my main document



ActionScript Code:
public function Main() {
           
            this.addEventListener(loadEvent.LOAD_COMPLETE,loadHandler)
var audioLoad:audioLoader=new audioLoader();
   

        }
        function loadHandler(e:loadEvent):void {
            trace("about to init"+e)
            init();
           
        }

It seems that the loadHandler from my main document never gets called because neither the trace traces or the init function executes?

Why might my main documnet class not be able to listen for the event I dispatch?

I tried changing bubbles for true to false but it didnt do anything. I get the feeling Im missing something very fundamental?

Global Event Listener
Hi,

I was wondering if its possible to have a global event listener in flash?

This site here seems to hint its possible about half way down the page

http://flashenabledblog.com/2007/06/...-user-actions/

But I couldn't really see if thats whats actually happening and if so how to implement it

Copyright © 2005-08 www.BigResource.com, All rights reserved