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




Event Listeners Galore >.<



I'm working on a flash object that is fairly simple, It has Three functions.
One for each type of event Listener. I want each button to essentially do the same thing, tween up or down, depending on which button has been selected and change color depending on which Event Listener has occurred.

I'm still working on the basic color changing principle, and am having some trouble with my event listeners, here's the code:


Code:
/*
-----------------

Buttons:
=================
about_btn
how_btn
what_btn
doing_btn

aboutHover_btn
howHover_btn
whatHover_btn
doingHover_btn
=================

-----------------
*/

stop();

// Starting Positions
about_btn.y = 0;
how_btn.y = 79;
what_btn.y = 158;
doing_btn.y = 237;

// The About Button

about_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
about_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
about_btn.addEventListener(MouseEvent.CLICK, Click);

about_btn.buttonMode = true;

// The How Button

how_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
how_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
how_btn.addEventListener(MouseEvent.CLICK, Click);

how_btn.buttonMode = true;

// The What Button

what_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
what_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
what_btn.addEventListener(MouseEvent.CLICK, Click);

what_btn.buttonMode = true;

// The Doing Button

doing_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
doing_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
doing_btn.addEventListener(MouseEvent.CLICK, Click);

doing_btn.buttonMode = true;

// Functions

function MouseOver (evt:MouseEvent):void {
evt.target.gotoAndPlay("mouseOver");
}

function MouseOut (evt:MouseEvent):void {
evt.target.gotoAndPlay("mouseOut");
}

function Click (evt:MouseEvent):void {
evt.target.gotoAndPlay("mouseOver");
if (evt.target.hasEventListener(MouseEvent.ROLL_OUT)) {
evt.target.removeEventListener(MouseEvent.ROLL_OUT, MouseOut);
evt.target.removeEventListener(MouseEvent.ROLL_OVER, MouseOver);
}
else {
doing_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
doing_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
about_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
about_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
how_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
how_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
what_btn.addEventListener(MouseEvent.ROLL_OVER, MouseOver);
what_btn.addEventListener(MouseEvent.ROLL_OUT, MouseOut);
}
}
Hopefully it's commented well enough, but basically what I'm doing is:
Adding event listeners to four of my buttons.Setting their starting y locations.changing it's color on RollOver and RollOut in the MouseOut and MouseOver functions.setting up my Click function so that that it checks if the selected button has the RollOver event listener and adding or removing that event listener.
I want the RollOver color to disappear when I click on a different button as well. I'm starting to wonder if creating 3 functions for each button would be a better idea..



KirupaForum > Flash > ActionScript 3.0
Posted on: 07-17-2008, 12:48 AM


View Complete Forum Thread with Replies

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

Adding Multiple Event Listeners To The ENTER_FRAME Event, Calling Different Functions
Is this going to slow my program down, or do all the references to these functions get added to a master ENTER_FRAME. I am trying to efficiently do this

Custom Event Handlers - Triggering Event Listeners On Other Objects
I'm trying to update an object whenever something happens in another object. At the moment, I have the second object explicitly calling an update function on the first object, but this seems a little sloppy and it strikes me that this is the sort of scenario where I should be using custom event handlers.

I'm not quite sure how they work though. My first assumption is that if I built two objects, one like this which fires off an event:


Code:
public class eventFirer extends Sprite
{

public function eventFirer():void
{
dispatchEvent(new Event("customEvent"));
}
}
...and one like this which updates whenever the custom event happens:


Code:
public class eventListener extends Sprite
{

public function eventListener():void
{
trace ("main");
addEventListener("customEvent", eventFired);
}

private function eventFired(e:Event):void
{
trace ("ok");
}
}
...then eventListener.eventFired would automatically be set off whenever a new eventFirer is created. This seems not to be the case though.

Can anybody enlighten me as to how custom events bubble between otherwise unrelated objects?

Using An Event Listeners Function At Will - Event Dispatching?
Hi,

I have a event listener that turns a camera on and off according to how much motion there is:


ActionScript Code:
camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);

private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}

All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?

Thanks

Using An Event Listeners Function At Will - Event Dispatching?
Hi,

I have a event listener that turns a camera on and off according to how much motion there is:

camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);

private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}

All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?

Thanks

Using An Event Listeners Function At Will - Event Dispatching?
Hi,

I have a event listener that turns a camera on and off according to how much motion there is:

camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);

private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}

All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?

Thanks

Event Listeners VS Event Functions
I'm working on a new project at work where there's lots of custom objects with lots and lots of event listeners. I keep finding myself saying, "why didn't they just use the built in objects with built in event handling?". However, from what I can see it seems like AS3 leans heavily towards using Event Listeners as opposed to putting event responsibility on the object itself (E.G. XML.onload). Is there an advantage to this (other than making it more Java like?) I've always favoured keeping the responsibility on the object itself because it seems like one less object to keep track of and also makes things feel more self contained. If I have 10 objects that fire 10 different events, I have to create 10 different event handlers (or 10 different case statements within the same event handler), whereas with self event handling, I just code in the event function.

Anyways, I wanted to open discussion to which method of event handling you prefer and why, and also what you believe the advantages to this. I was searching google for previous discussions on this but I couldn't seem to find anything, so I thought I'd get the ball rolling! Looking forward to reading these, try not to be too elitist in your posts!!

Event Handlers Vs. Event Listeners
I'm having trouble understanding why listeners are necessary, beyond tying events to objects "conceptually." Are listeners used that often? What am I missing?

[F8] Help Regarding Event Listeners
Hello All,
I would like some help with an effect I am trying achieve.
I am controlling the text displayed in a dynamic text field with the position of the mouse.
For Example:
[code]if(_root._ymouse <100) {
_root.variable=TextOne;
} else if (_root._ymouse >100) {
_root.variable=TextTwo;
}
I would like, every time the text changes a sound to be played. I know about Sound Objects and etc, I am just wondering the best way to call a function when the text in the text field changes. Would it be with an EventListener or something completely different?

If so, can yu give me an idea how I would code it, I dont have much experience with Event Listeners.

Thankyou v.much in advance.

Help With Event Listeners
Hello World!

This is my first post. I'm a professional junior programmer in C++ and Jscript, but I'm under something of a time crunch to figure out if Flash is the rapid-prototyping tool I should be using, so I appeal to your understanding if I haven't researched the problem thoroughly enough.

I've come across a problem with event handlers, which aren't behaving the way that I would expect them to. Consider this code:


Code:
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;

public class MapTile extends MovieClip
{
var bmp: Bitmap;
var scale:Number;

public function MapTile(canvas)
{
var temp:whiteBloodCell = new whiteBloodCell(0, 0);
bmp= new Bitmap(temp);

scale= canvas.SCREEN_WIDTH / canvas.TILE_SIZE / canvas.MAP_TILES;

bmp.scaleX = scale;
bmp.scaleY = scale;
bmp.x = 100;
bmp.y = 100;
bmp.alpha = 0.34;

canvas.addChild(bmp);
addEventListener(MouseEvent.CLICK, onMouseOver);
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
trace("Excuse Me");

}

public function onMouseOver(e:MouseEvent)
{
trace("you are excused");
bmp.alpha = 1.0;
bmp.scaleX = 1;
bmp.x += 100;
}
}
}
What I want is this bitmap/movieclip to have rollover effects. This object is instantiated by my Main object, which properly handles other events. So, I'm a little confused. I have an object which handles events, but the objects in that object don't. Extending the Main class seems like bad design. What I really want to do is extend the Bitmap class so that I can do some particle effects on it, without having to bother Main.

Is the Main object acting like an observer, so it must pass a message to it's children?

Event Listeners
Do eventlistener only work while you're at the frame that you have established them on? It seems like...

I'm establishing a button and an event listener on mouse up in frame 2, but even though empty frame up to frame 50 for that layer, the event listener seems gone when I'm on frame 7 where I'm using that same button. It works when I'm on frame 2 and the function still exists on frame 7, but does not fire when I click the button. Why?

Allan

Event Listeners
Maybe I am missing something here. But what I am trying to do is cause a swf to advance one frame after an FLVPlayback component is finished playing the movie. What is happening is, well, nothing. The movie plays just fine. I have added some test code:

import mx.video.FLVPlayback;
var clip:FLVPlayback;

function finishedClip()
{
trace('finished');
}

clip.addEventListener("complete", finishedClip());

the FLVPlayer is labled clip. As soon as I publish the swf, it will trace 'finished'. I have tried other events such as stop, playing, ready.... they all trace at the load of the swf and not when the event is happening. It looks as though nothing knows what the FLVPlayer is doing. If anyone has any clue as to what is going on here, Please let me know. Thnx!!

AC

Event Listeners
I know other people are having the same trouble with this and I've found a few threads that seem to solve the problem, but I'm not having any luck with it. I would like to detect the end of an .flv so I can add actions afterwards. Maybe someone here can help me out?

Code:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.setBufferTime(5);
myVideo.attachVideo(ns);
path = "videos/";
ns.play(path+"test.flv");
var listenerObject:Object = new Object();
// listen for complete event
listenerObject.complete = function(eventObject:Object):Void {
trace("flv complete....");
};
myVideo.addEventListener("complete", listenerObject);

Help With Event Listeners
Flash CS3, actionscript 2.0

I have a timeline animation that I am trying to convert to actionscript. Basically there are 8 movie clips that I have added to the timeline that fade in at different times. I have the code for each of the tweens figured out (var laugh:Tween = new Tween(laugh_mc, "_alpha", Strong.easeIn, 0, 100, 17, false) but I need one to start one, then when its finished, go to the next one without using go to and play. I'm a bit of a newbie to actionscript so if someone could provide an example, it would be much appreciated.

Thanks!

Event Listeners?
Is it possible to remove an event listener on a class, from outside of that class?

Let's say I have a class and do this.

thisClass.addEventListener(Event.ENTER_FRAME, eFrameRight)

could I remove it from outside of "thisClass"
Because I wanna remove the child that is "thisClass" and it's event listeners, but it isn't working.

Event Listeners
Hello,
Does setting an object with an event listener to Null remove the event listener as well?

Thanks!

Event Listeners And Components In V.2
I am having trouble trying to figure out the correct coding format for calling a function after a selection on a Combo Box is made in V.2 Actionscript.

For example, if I wanted to change the rotation of a MC by what option a user selected in a COmbo Box. I know that in V.1 the code would be something like this on frame 1 of the movie:


function generalHandler(currentComponent){
if (currentComponent._name == "rotationValue" ) {
mySquare._rotation = currentComponent.getValue();
}
}

FYI -
rotationValue = Instance Name of the COmbo Box
mySquare = Instance name of the Square MC
generalHandler = Name of Function which is linked in the Change HAndler Parameter in FLash MX, but the change handler is not there in MX 2004 which I am working with.

What I am aware of is that in MX2004 you need to add a component listener event to this, instead of using the Change Handler option. The problem is, I am completely confused on the code needed to do this.

I came up w/ something like this for the V.2 Actionscript code:

rotation = new Object();
rotation.change = function (evt){
mySquare._rotation = evt.target;
}
rotationValue.addEventListener ("change", rotation);


I am not even sure how close this is, but it doesn't work I know that much.
Can anyone get me starightened out on this new method? I think it is the theory of what is going on that eludes me. I have looked on the boards as well as in Macromedia Flash MX2004 help. I found a few things, but haven't been able to smooth out the confusion.

Any help would be appreciated

Thanks
dutchoh1

OnRelease And Event Listeners
Ok, having a real problem with this:

I have a movie clip.

In that movie clip is a Button.

The movie clip's onLoad method trys to add an event listener for the onRelease method of the button.

It does not work.

I tried addListener and addEventListener methods and nothing.

My listener object has a onRelease method, but the button is not broadcasting the event to the listener.

??

thanks for the help,

sprout

Question On Event Listeners
ok so i got this piece of code i want to encorporate into a function. the original code was designed to use an onClipEvent(enterFrame) event. the code is also written on the movieclip time line. how do i create a listener, for the enterFrame event and, that will be used inside a function on the main timeline on the first frame of my movie???


thanx

mickey

Cue Points And Event Listeners
So I have this action script, an event listener, which checks the FLV and when come to the end of the FLV It performs another task. My task being nextFrame();

flvPlayback.addEventListener("complete",this.compl ete);
function complete(evt:Object):Void {
nextFrame();
_root.blackbox._yscale, 1, 1, true);
}

The question I have is does anyone know how to do the same thing but instead of the event listener looking for the end of the flv it's looking for the cue point? I named my cuepoint "scare_now" I'm not sure if that matters though.

If anyone can help I'll bake you some brownies.

Event Listeners Not Working Please Help
Hi people im really stcuk here ive make an event handerler for my leftbat class but it does not work, when I publish it ill press all the keys but nothing happens. Can someone have a look and sort it out for me? Ive got no idea what the problem is as im only starting to learn AS3 ive attached the files and any help would be brillient

Too Many Event Listeners - Good Or Bad?
Hi guys

Quick question for you all regarding optimization and speed.
If you have a game with a lot of sprites, particles, etc is it better to give each sprite/particle its own Enter Frame event listener which updates its position? OR would it better to control all frame updates for all movieclips from one single event listener in the main timeline?

Which one would be better for speed and faster frame rates?

Variables And Event Listeners
I have 15 buttons that have listeners attached. Btn1, Btn2, Btn3, etc.

This is ideally what I'd like to have happen, but I can't figure the code out.

var a:var = 1;

Btn+a.addEventListener(MouseEvent.CLICK, onNext+a);
function onNext+a(evt:MouseEvent):void {
MC+a.visible = true;
a = a+1;
}

Cheers

Event Listeners- Move MC
ok..sorry for the post, i havent looked at flash for a while and what id learnt is forgotten and what i remember is proberly out dated!

I want a full screen flash movie with a mc position in a specific place. Upon a button action, how can a move 'gracefully' this mc, say 200 pixels or a % to the left?

What i used to do for the original setup and position was


ActionScript Code:
Stage.scaleMode = "noScale";
Stage.align = "TL";
Stage.addListener(this);

this.onResize = function ()
{
    movie._x=Stage.width*(50/100);
    movie._y=Stage.height*(98/100);
    menu._x=Stage.width*(50/100);
    menu._y=Stage.height*(50/100);
};

this.onResize();

Many thanks in advance

Removing Event Listeners
Hi,

If I add an event listener like this:

myClass.addEventListener("onAction", Delegate.create(this, myFunction));

Can I remove it?

The problem is that the listener object is annonymous. So I can't reference it as the second argument in removeEventListener.

Thanks

FLV Cue Points And Event Listeners.
Im trying to create a file which sends a movie clip to key frames when cue points are hit in an flv playback component on the main stage. Here is the code I'm using at the moment...

stop();

var displayListener:Object = new Object();
displayListener.cuePoint = function(eventObj:Object) {
var index = String(eventObj.cuePointName);

if (index="introductionText") {
_root.animationMovie.gotoAndStop(2);
}
if (index="bayCollection") {
_root.animationMovie.gotoAndStop(3);
}
if (index="dualWaterfall") {
_root.animationMovie.gotoAndStop(4);
}
};
screen.addEventListener("cuePoint", displayListener);

The plan is that when the movie (screen) hit the right cue points, then the animationMovie movieclip jumps to the frames in the code.

Everything is working fine apart from the fact that as soon as the first cue point is hit in the video, the animationMovie jumps straight to the last frame listed, which is frame 4 for the purposes of this post. Every time I either add or remove one of the if statements, the animationMovie still jumps to the last if statement and carries it out.

I'm sure that I'm missing something very simple here, can anyone help?

Removing Event Listeners
Hi,

I have a manager class that instanciates multiple objects. To each object it adds an eventListener, listening for the event "onExit". When the object leaves the screen it fires "onExit", and the manager destroys it. My problem is how to remove its listener.

At the moment I am pushing the object and the listener into an Array, then when an "onExit", matching the event object's target to the object in the Array and thus retrieving the relevent listener allowing the manager to remove the listener.

Is there a more efficient way of keeping track of which listener goes with which object?

Tracking Event Listeners
Hi there all,

I have a question, does anybody know of a way to trace or list all of the active event listeners on an object?

JJay.

Managing Event Listeners
Can anyone outline some strategies for managing Event listeners. It seems that this is a key element to getting the most out of AS3.

I have a project that creates Tween objects periodically to animate objects. I'm curious if I should be deleting these after each use. The next time I animate an object I create a new Tween.

Each time I create a Tween I'm adding an event listener for that Tween, sometimes two. How fastidious should be about cleaning these up?

2 Event Listeners For Loader?
I'm trying to a load a SWF file into my movie, add values to the text fields in the loaded SWF file and then print the SWF file. I have 2 listeners on the Loader - 1- to add the text and 2- to print it... How can this be done so that there is one listener to check when values were added to the text fields when it's done loading and then another listener to print after the values have been added to the text fields?

Right now I know it's very messy code. It's printing and then adding the text values to the SWF after printing.


ActionScript Code:
private function printCertificate(event:MouseEvent):void {
            addChild(princCertificate);
            //ATTACH CERTIFICATE
            var certLoader:Loader = new Loader();
            configureListeners(certLoader.contentLoaderInfo);
           
            var request:URLRequest = new URLRequest(certificateUrl);
            certLoader.load(request);
           
            princCertificate.addChild(certLoader);
           
            certLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
            function onLoad(e:Event):void {
                var cert:MovieClip = MovieClip(certLoader.content);
                cert.percentScore_txt.text = "This should work, though i haven't tried it myself :)";
                cert.course_txt.text = "So please tell me if it works or not, it will be helpful to me :)" ;
                addChild(cert);
                trace('text has been added to certificate');
            }
        }
       
        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
           
            //START PRINTING CERTIFICATE AFTER CERTIFICATE IS LOADED
            if (certPrintJob.start()){
                trace('printing has started');
                if(certPrintJob.orientation == PrintJobOrientation.PORTRAIT){
                    princCertificate.rotation = 90;
                }
               
                try{
                    certPrintJob.addPage(princCertificate);
                }
                catch (error:Error){
                    //Handle error,
                }
                certPrintJob.send();
            }
            else{
                trace("print job canceled");
            }
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

Keyboard Event Listeners
I'm definitely suffering with the lack of Keyis.Down! Anywhoo here is my code...


ActionScript Code:
public function Crung() {
    this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
}
   
public function onKeyPressed(evt:KeyboardEvent):void {
    switch (evt.keyCode) {
        case Keyboard.RIGHT:
            this.x += 1;
            break;
        }
    }
}

This does nothing, and I'm thinking its because this isn't the document class and the event listener needs to be on the stage. 'public function Crung() {' is the constructor for the class Crung. An instance of Crung is created in Level1.as. And an instance of Level1 is created in Main.as which is the document class. So...

Main.as
...Level1.as
......Crung.as

Crung is basically a MovieClip which the user moves around the stage using the keyboard keys.

Any help in going about this? Not necessarily moving him around, just getting the listener to do anything in Crung.as

Copy Event Listeners
Hi,

I really hope someone knows this. If I have a display object with various event listeners assigned to it and I then create another display object dynamically which I want to have exactly the same event listeners as the first. How do I do this?

thanks!

Event Listeners And Z Index
Hey all,

I have two movieclips on the stage - currently overlapping eachother (however one bigger than the other).
At default blue_mc should be visible / on "top" / in front, but when I click blue_mc, - black_mc should be brought on "top" and blue_mc should be hidden.

So im guessing I have to use some sort z-index to bring movieclips in front and back? And furthermore some alpha to hide the non-active movieclip?

I managed to put together the following with my poor AS skills


Code:
blue_mc.alpha = 0;

black_mc.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
trace("Black square");
blue_mc.alpha = 1;
black_mc.alpha = 0;
}


blue_mc.addEventListener(MouseEvent.CLICK, clickHandler2);
function clickHandler2(event:MouseEvent):void {
trace("Blue square");
black_mc.alpha = 1;
blue_mc.alpha = 0;
}
However although blue_mc is visible, i'm still getting the Black square trace. I'm guessing it's because black_mc's z-index/level is still in front.

Hope someone can shed some light on this for me

Event Listeners Not Working Or... :S
hi AS community.

ive got a problem getting a socket connection to work.

i got an example chat script in as2, and got it to work.
socket server is programmed in java and also works.

now i made as3 version of the same thing, and it doesnt work.
it connects, doesnt give any errors, nothing.

here is the first example code that works


Code:
mySocket = new XMLSocket();
mySocket.onConnect = function(success) {
if (success) {
msgArea.htmlText += "<b>Server connection established!</b>";
} else {
msgArea.htmlText += "<b>Server connection failed!</b>";
}
};
mySocket.onClose = function() {
msgArea.htmlText += "<b>Server connection lost</b>";
};
XMLSocket.prototype.onData = function(msg) {
msgArea.htmlText += msg;
};
mySocket.connect("192.168.1.68", 4444);
//--- Handle button click --------------------------------------
function msgGO() {
if (inputMsg.htmlText != "") {
mySocket.send(inputMsg.htmlText+"
");
inputMsg.htmlText = "";
mySocket.send("asdfff");
}
}
pushMsg.onRelease = function() {
msgGO();
};

and here is the AS 3 that does nothing
it should send a text to socket every time i click on an object on a stage. nothing happens


Code:
var xml_s:XMLSocket;
xml_s=new XMLSocket();
xml_s.connect("192.168.1.68",4444);
//Security.loadPolicyFile("E:Program FilesApache GroupApache2htdocspubliccrossdomain.xml");
xml_s.addEventListener(ProgressEvent.PROGRESS,prog);
xml_s.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
xml_s.addEventListener(Event.CONNECT,connected);
xml_s.addEventListener(DataEvent.DATA,arrived);
//xml_s.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,arr);
function onResponse(event:ProgressEvent):void
{
trace("GOT RESPONCE");
feed.text="GOT RESPONCE";
}
function prog(event:ProgressEvent):void
{
feed.text="prog";
}
function connected(Event):void
{
feed.text="connected";
xml_s.send("welcome socket server");
}
//test send is a movieclip on stage
TestSend.addEventListener(MouseEvent.CLICK,klick);
function klick(event:MouseEvent):void
{
//xml_s.send( new XML("data arrived
"));
xml_s.send("data .");
}
function arrived(event:DataEvent):void
{
trace("data arrived :D");
feed.text="data arrived :D";
}
there are no error listeners. i removed them only in this post. they exist in the script.

Listing Event Listeners
Greetings!

Is there a way to enumerate all the event listeners currently added to an event dispatcher?

Thanks.

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


Code:
private function layoutTopics(modNum:Number, attachTo:MovieClip):void {
topicLength = MainMenu.modArr[modNum].topicArr.length;
if (Interface._ui != null) {
pageLength = Interface._ui.pageArr.length;
}
for (var t:Number = 0; t<topicLength; t++) {
if (modNum == 0 && t == 0) {
//Splash page should not be on the Menu screen
} else {
topic_mc = new Topic();
attachTo.addChild(topic_mc);
topic_mc.name = "topic"+t;
topic_mc.title.text = MainMenu.modArr[modNum].topicArr[t].header;
//Special placement for module 0
if (modNum == 0) {
topic_mc.y = (topic_mc.height-1)*t+17;
} else {
topic_mc.y = (topic_mc.height-1)*t+75;
}
topic_mc.x = 12;
var topNum:Number = t+1;
topic_mc.id = getPageArrIndex(modNum, topNum);
topic_mc.moduleNumber = modNum;
topic_mc.topicNumber = topNum;
topic_mc.buttonMode = true;
topic_mc.useHandCursor = true;
topic_mc.mouseChildren = false;
topic_mc.addEventListener(MouseEvent.CLICK,loadTopic);

// ADDING A DELAY TO ALLOW TIME FOR THE "topic_mc" TO INSTANTIATE
topic_mc.addEventListener(Event.ENTER_FRAME, addDelay);
//trace(topic_mc.name);
}
function addDelay(evt:Event):void {

evt.target.removeEventListener(Event.ENTER_FRAME, addDelay);
//trace(evt.target.name);


//if available
if (previousTopicState == "complete") {
evt.target.gotoAndStop("available");
previousTopicState = "incomplete";
}
//if visited/completed
if (checkTopicComplete(modNum, topNum)) {
evt.target.gotoAndStop("completed");
previousTopicState = "complete";
} else {
//if in progress/incomplete topic
if (Interface._ui != null) {
if (evt.target.moduleNumber == Interface._ui.currentModule) {
if (evt.target.topicNumber == Interface._ui.currentTopic) {
evt.target.gotoAndStop("inProgress");
}
}
}
}
}
}
}
Using

Code:
evt.target.removeEventListener(Event.ENTER_FRAME, addDelay);
doesn't really work - the listeners keep running. How do I call the objects properly to remove the listeners?

Event Listeners And Overlapping MC's
Im sure this has been asked a million times, so forgive me but I cannot seem to find an answer or my search query is wrong.

I am using Tweener for animation.

I have 2 MC's on my stage. I have an event listener for my main MC (MOUSE_OVER, MOUSE_OUT) that triggers Tweener to animate another MC on top of the main clip. The problem is that when it overlaps the listener no longer works, and tried to execute the MOUSE_OUT. I understand why its not working, I just cant find a solution. Here is the code and a simple FLA.



ActionScript Code:
import caurina.transitions.Tweener;

square.addEventListener(MouseEvent.MOUSE_OVER, RollItIn, false, 0, true);
square.addEventListener(MouseEvent.MOUSE_OUT, RollItOut, false, 0, true);

function RollItIn(evt:MouseEvent):void {
    Tweener.addTween(circle, {y:40, time:.25, transition:"easeInOutSine"});
}
function RollItOut(evt:MouseEvent):void {
    Tweener.addTween(circle, {y:200, time:.25, transition:"easeInOutSine"});
}

Thanks a million and please dont shoot me

Using Event Listeners In A Class
Hello, I've been trying to get into classes recently, and have hit a problem using event listeners in a class.

I've been triggering a function in my class on a FileReference event (also in my class). The problems is that the function runs, but can't see any of my class variables.

Below is a simplified example, which will output: "Message is: undefined"

Thank you for any help you can give me,

Cheers,

James

Code from flash file:

Code:
var myTest = new Test();
Code from Test.as:

Code:
import flash.net.FileReference;

class Test{

private var msg:String;
private var file:FileReference;
private var fileListener:Object;

public function Test(){
msg = "Hello, Can You See Me?";
file = new FileReference;
fileListener = new Object();
file.addListener(fileListener);
fileListener.onSelect = selectedFiles;
file.browse();
}

public function selectedFiles(f:FileReference){
trace("Message is: " + msg);
}
}

FLV Cue Points And Event Listeners
Im trying to create a file which sends a movie clip to key frames when cue points are hit in an flv playback component on the main stage. Here is the code I'm using at the moment...

stop();

var displayListener:Object = new Object();
displayListener.cuePoint = function(eventObj:Object) {
var index = String(eventObj.cuePointName);

if (index="introductionText") {
_root.animationMovie.gotoAndStop(2);
}
if (index="bayCollection") {
_root.animationMovie.gotoAndStop(3);
}
if (index="dualWaterfall") {
_root.animationMovie.gotoAndStop(4);
}
};
screen.addEventListener("cuePoint", displayListener);

The plan is that when the movie (screen) hit the right cue points, then the animationMovie movieclip jumps to the frames in the code.

Everything is working fine apart from the fact that as soon as the first cue point is hit in the video, the animationMovie jumps straight to the last frame listed, which is frame 4 for the purposes of this post. Every time I either add or remove one of the if statements, the animationMovie still jumps to the last if statement and carries it out.

I'm sure that I'm missing something very simple here, can anyone help?

OnEnterFrame And Event Listeners
Hi again,

I need some help constructing one of my buttons. I want my button to increase size when I rollover it, and decrease size when I move my cursor out of the button. I don't know how to do this smoothly, for example if I rollover my cursot really fast I don't want the button to jump to the bigger size and then start decreasing. Is it a good way to use prevFrame and nextFrame for this? My problem is that I don't know how to implement my onEnterFrame function....any help? My code so far...

Any help will be appreciated.







Attach Code

homebtn.addEventListener(MouseEvent.ROLL_OVER, homeRoll);
homebtn.addEventListener(MouseEvent.ROLL_OUT, homeRoll);


function homeRoll(evt:MouseEvent):void {
if (evt.target == MouseEvent.ROLL_OVER) {
homebtn.addEventListener(Event.ENTER_FRAME, enterFrameHandler1);
} else {
homebtn.addEventListener(Event.ENTER_FRAME, enterFrameHandler2);
}
}
function enterFrameHandler1():void {
homebtn.nextFrame();
}
function enterFrameHandler2():void {
homebtn.prevFrame();
}

Trace Event Listeners
hi, i was wondering if it's possible to trace out any listeners that have been registered? i have so many listeners going on right now, and at a current point in my program, there is a listener that isn't being removed. i thought it would be a lot easier to debug my application but tracing out what objects are registered with what events. i also have the feeling that i'm double-adding an event listener somewhere. is that possible? thanks!

Overlaying Event Listeners
Hi,

I am reposting my question since i probably didn't explain myself very well the first time.

I have to Sprites with mouse listeners that overlap.

I'll try illustrating it:

_____________
| | - Big Sprite behind
| _______|____
| | | |
| | | | - Small sprite on top
| |_______|____|
|_____________|

Now my question is when i'm over both sprites with my mouse
is it possible for both of them to recieve a MOUSE_OVER event
at the same time?

Thank you,

tamagorci

Adding Event Listeners
I have a Guest class like this:-


Code:
class Guest{
private var guest_mc:MovieClip;
private var guestName: String;
private var rfid:Number;


public function Guest(name:String, target:MovieClip, depth:Number){
guest_mc = target.attachMovie("guest", name, depth);
guest_mc.addMouseListener('mouseMove', this);
}

public function setPosition(x:Number, y:Number){
guest_mc._x = x;
guest_mc._y = y;
}

public function setGuestName(guestName:String){
this.guestName = guestName;
}

public function getGuestName ():String{
return guestName;
}

public function setRfid(rfid:Number){
this.rfid = rfid;
}

public function getRfid ():Number{
return rfid;
}


public function mouseMove ():Void {
trace("Moved the Mouse");
}

}
Since I would have many instances of Guest created dynamically, I am iterating througha for loop to make life easier

Code:
var numOfPeople = names.length;
for(var i=0; i<numOfPeople; i++){
var someguest="guestclip" + i;
var x = random(300);
var y = random(300);
var statusNum = charStatus[i];
if(statusNum == "1"){
this[someguest] = new Guest("guest"+i, this, i)
this[someguest].setPosition(x,y);
this[someguest].setGuestName(names[i]);
}
When a guest instance is clicked, I would like it to identify itself, that is perhaps return the guestName that I set using the OOP technique. The big question is- why doesnt the dynamic movie clip respond to the mouse click although I have a MouseListener added to it? I want to add the mouse listener in the class definition since it would be easier to handle events for multiple instances(i think so, others might think otherwise).

Event Listeners (which Is Faster)
Hey,
I have this script which is effectivly doing 2 things every frame;
- checking where the mouse is;
- checking where to move somthing depending on the mouse and stage height;

The first part will always execute in my Event.ENTER_FRAME function. However, the second part will only execute if the stage height is smaller than whatever. The question is, is it faster to;
- Make 2 seperate Event.ENTER_FRAME listeners when needed
- OR -
- Make 1 large one that constantly checks if it should move depending on the stage height.

How does this work if I say have many event listeners? Is it more friendly to make many small ones or better to make fewer big ones, even if some parts of these simply waste processing time.

Also another thing, I have an embeded font working fine, but somtimes it moves up about 1 pixel then down again depending on a glow filter I am using which isnt even applied to the text. Setting the quality to 3 stops it, but at 2 it moves. There is no logic for this obviously and it is a glitch. Wierd

Thanks for reading/helping,
Dan

Generic Event Listeners
I have an array of objects, all the same type and I want them all to utilize an event listener, how can i do this? also is there an method like objectType(), so that when i go through the array I can say if (objects[i].objectType(blah)) ?

Cue Points And Event Listeners
So I have this action script, an event listener, which checks the FLV and when come to the end of the FLV It performs another task. My task being nextFrame();

flvPlayback.addEventListener("complete",this.compl ete);
function complete(evt:Object):Void {
nextFrame();
_root.blackbox._yscale, 1, 1, true);
}

The question I have is does anyone know how to do the same thing but instead of the event listener looking for the end of the flv it's looking for the cue point? I named my cuepoint "scare_now" I'm not sure if that matters though.

If anyone can help I'll bake you some brownies.

Event Listeners/Dispatchers...
Hello!

Im still a tad sketchy on how event listeners/dispatchers are meant to be used and how they work exactly. Ive scoured the internet but like usual i get a list of 3 common sites that dont really directly answer any questions ive got, so if any of you guys can answer i would be greatly appreciative!

1) When an event dispatcher/listener is created is it only able to dispatch and listen to events within its current scope, or are events global automatically and heard by any event listener? i.e Class A dispatches a function that Class C should listen for.


2) When you enter your function in the eventlistener, should you always do the full path to the function or just a short path? i.e Class A wants to listen for a COMPLETE event, then trigger the method doStuff(), so would it be:


Code:
addEventListener(Event.COMPLETE, this.doStuff);

Code:
addEventListener(Event.COMPLETE, doStuff);
Funny thing is the above doesnt acctually work within a class, however if you are using a loader and use the .contentLoaderInfo.addEventListener... it does, can anyone explain why this works and the normal declaration doesnt?


3) If there are 3 listeners all listening out for the same event in the same scope however they all trigger different functions, would 1 event dispatch trigger them all? Is there a way that you can define which listener you want to target...?


4) This ones kinda related to question 1, but if you were to make a global event handler and you made it listen for events then dispatch them to specific objects methods, how would you link to the specific objects function as chances are it would be out of scope, would you pass it a function pointer?

There may be more questions based off the answers here, but these are the simplest questions that i can think of that would greatly benefit me if i knew the answers!

Multiple Event Listeners
Hi

I'm sure this is a simple problem, but I can't see it.

I have dynamically created multiple flv playback instances which all play different video clips simultaneously. This all works fine:

Code:
for (var i:Number=0; i<10; i++) {
this["videoPreview_mc_"+i].attachMovie("FLVPlayback", "video_flv", this["videoPreview_mc_"+i].getNextHighestDepth());
}
I am trying without success to add listeners to replay each flv as it ends (to loop the preview). I thought something like this would work, but none of the flvs replay and the trace is "video complete 9":

Code:
for (var i:Number=0; i<10; i++) {
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
this["videoPreview_mc_"+i].video_flv.seek(0);
this["videoPreview_mc_"+i].video_flv.play();
trace("Video complete"+i);
}
this["videoPreview_mc_"+i].video_flv.addEventListener("complete", listenerObject);
}
Thanks in advance.
Colin

How Can I Add Event Listeners In A Loop?
How can I add event listeners in a loop?

For example I have the following code....
How can I make this into a loop?


Code:
this.k0.addEventListener(MouseEvent.MOUSE_OVER, this.k0RollOver);
this.k1.addEventListener(MouseEvent.MOUSE_OVER, this.k1RollOver);
this.k2.addEventListener(MouseEvent.MOUSE_OVER, this.k2RollOver);
this.k3.addEventListener(MouseEvent.MOUSE_OVER, this.k3RollOver);
this.k4.addEventListener(MouseEvent.MOUSE_OVER, this.k4RollOver);
this.k5.addEventListener(MouseEvent.MOUSE_OVER, this.k5RollOver);
this.k6.addEventListener(MouseEvent.MOUSE_OVER, this.k6RollOver);
this.k7.addEventListener(MouseEvent.MOUSE_OVER, this.k7RollOver);
this.k8.addEventListener(MouseEvent.MOUSE_OVER, this.k8RollOver);
this.k9.addEventListener(MouseEvent.MOUSE_OVER, this.k9RollOver);

private function k0RollOver(event:MouseEvent):void { this.k0.key.gotoAndPlay("on"); };
private function k1RollOver(event:MouseEvent):void { this.k1.key.gotoAndPlay("on"); };
private function k2RollOver(event:MouseEvent):void { this.k2.key.gotoAndPlay("on"); };
private function k3RollOver(event:MouseEvent):void { this.k3.key.gotoAndPlay("on"); };
private function k4RollOver(event:MouseEvent):void { this.k4.key.gotoAndPlay("on"); };
private function k5RollOver(event:MouseEvent):void { this.k5.key.gotoAndPlay("on"); };
private function k6RollOver(event:MouseEvent):void { this.k6.key.gotoAndPlay("on"); };
private function k7RollOver(event:MouseEvent):void { this.k7.key.gotoAndPlay("on"); };
private function k8RollOver(event:MouseEvent):void { this.k8.key.gotoAndPlay("on"); };
private function k9RollOver(event:MouseEvent):void { this.k9.key.gotoAndPlay("on"); };

Removing Event Listeners
I have just found out I can do this





myMovie_mc.addEventListener(MouseEvent.CLICK, function()
{ parent.gotoAndPlay(1);


});





Up untill now I have been creating named functions, this will save a few lines of code, but how do I remove this event listener?

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