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




AS3: Adding Parameter To EventListener



hi everybody.


i'd like to know how to pass a parameter to my function through an eventListener.
to illustrate, I've made this example:
http://campjohn.dk/AS3/addingParamet...ntListener.swf

by clicking the boxes on the left, the bigBox centrered changes color.
nice!
right now, I have to use a if else-loop:


Code:
//imports
import caurina.transitions.Tweener;

this.blueBox.addEventListener(MouseEvent.CLICK, changeColor);
this.redBox.addEventListener(MouseEvent.CLICK, changeColor);
this.yellowBox.addEventListener(MouseEvent.CLICK, changeColor);

function changeColor(e:Event):void {
trace("CLICKED: e.target.name = "+e.target.name);
if(e.target.name == "blueBox"){
Tweener.addTween(this.bigBox, {_color:0x0000FF, time:1, transition:"linear"});
trace("changing color to blue");
} else if(e.target.name == "redBox") {
Tweener.addTween(this.bigBox, {_color:0xFF0000, time:1, transition:"linear"});
trace("changing color to blue");
} else if(e.target.name == "yellowBox") {
Tweener.addTween(this.bigBox, {_color:0xFFFF00, time:1, transition:"linear"});
trace("changing color to blue");
} else {
trace("this shouldn't be possible");
}
}
can I somehow change the example above so it passes the color to use to the function as a parameter instead?

thanks
felisan



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 05-29-2008, 09:09 AM


View Complete Forum Thread with Replies

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

AS3: Adding Parameter To EventListener
hi everybody.


i'd like to know how to pass a parameter to my function through an eventListener.
to illustrate, I've made this example:
http://campjohn.dk/AS3/addingParamet...ntListener.swf

by clicking the boxes on the left, the bigBox centrered changes color.
nice!
right now, I have to use a if else-loop:


Code:
//imports
import caurina.transitions.Tweener;

this.blueBox.addEventListener(MouseEvent.CLICK, changeColor);
this.redBox.addEventListener(MouseEvent.CLICK, changeColor);
this.yellowBox.addEventListener(MouseEvent.CLICK, changeColor);

function changeColor(e:Event):void {
trace("CLICKED: e.target.name = "+e.target.name);
if(e.target.name == "blueBox"){
Tweener.addTween(this.bigBox, {_color:0x0000FF, time:1, transition:"linear"});
trace("changing color to blue");
} else if(e.target.name == "redBox") {
Tweener.addTween(this.bigBox, {_color:0xFF0000, time:1, transition:"linear"});
trace("changing color to blue");
} else if(e.target.name == "yellowBox") {
Tweener.addTween(this.bigBox, {_color:0xFFFF00, time:1, transition:"linear"});
trace("changing color to blue");
} else {
trace("this shouldn't be possible");
}
}
can I somehow change the example above so it passes the color to use to the function as a parameter instead?

thanks
felisan

AS3: Adding Parameter To EventListener
hi everybody.


i'd like to know how to pass a parameter to my function through an eventListener.
to illustrate, I've made this example:
http://campjohn.dk/AS3/addingParameterToEventListener/addingParameterToEventListener.swf

by clicking the boxes on the left, the bigBox centrered changes color.
nice!
right now, I have to use a if else-loop:

Code:

//imports
import caurina.transitions.Tweener;

this.blueBox.addEventListener(MouseEvent.CLICK, changeColor);
this.redBox.addEventListener(MouseEvent.CLICK, changeColor);
this.yellowBox.addEventListener(MouseEvent.CLICK, changeColor);

function changeColor(e:Event):void {
   trace("CLICKED: e.target.name = "+e.target.name);
   if(e.target.name == "blueBox"){
      Tweener.addTween(this.bigBox, {_color:0x0000FF, time:1, transition:"linear"});
      trace("changing color to blue");
   } else if(e.target.name == "redBox") {
      Tweener.addTween(this.bigBox, {_color:0xFF0000, time:1, transition:"linear"});
      trace("changing color to blue");      
   } else if(e.target.name == "yellowBox") {
      Tweener.addTween(this.bigBox, {_color:0xFFFF00, time:1, transition:"linear"});
      trace("changing color to blue");         
   } else {
      trace("this shouldn't be possible");
   }
}

can I somehow change the example above so it passes the color to use to the function as a parameter instead?

thanks
felisan

Trouble Adding Eventlistener In Loop
I'm having trouble adding this eventlistener in a simple loop. Can somebody tell, why the eventhandler doesn't get triggered?


Code:
// handler
function countryHandler(e:MouseEvent)
{
trace(e.currentTarget.name);
}

// add eventlistener loop
for (var i:Number = 0; i < isoCountriesArr.length; i++)
{
var tempId:String = isoCountriesArr[i];
if (map_mc.getChildByName(tempId) != null)
{
var tempCountryMc:MovieClip = MovieClip(map_mc.getChildByName(tempId));
countryArray.push(tempCountryMc)
tempCountryMc.addEventListener(MouseEvent.CLICK, countryHandler);
}
}

Adding Eventlistener At Runtime, Error #1006
Hii guys
I'm a newbie in AS3 working with flex
I have a custom control named as Frame
I'm adding a event listener to frame object
and have to call the function for event handling
where I want the objFrame, where I could do some functioning
on it

I dont know how to add a listener to a object at runtime n calling the
listener function and passing some values to it.


Below is my code
I'm getting the error
TypeError: Error #1006: value is not a function.
at presentation/FrameClick()[E:aFlex workspaceCreatorsrcpresentation.mxml:82]


plz help me out
its urgent


some function
{

for(var intD:int=0;intD<intNoOfFrames;intD++)
{
var objTmpFrame:Frame=new Frame();
objTmpFrame.height=intHeight;
objTmpFrame.width=intWidth;
strFrameId="FrameNo:"+(intD+1);
objTmpFrame.id=strFrameId;
objTmpFrame.graphics.beginFill(0x0000ff);
objTmpFrame.addEventListener(MouseEvent.CLICK,Fram eClick); //adding the
//listener at runtime n calling the function frameclick
MainMiddleVbox.addChildAt(objTmpFrame,intD);
}
lblCurrentFrame.text="Frame:1";
}


private function FrameClick(event:MouseEvent):void
{
LINE:82 var objCurrentFrame:Frame=event.currentTarget() as Frame;
var objAmanda:amanda=new amanda();

}


thanks in advanx

[F8] Adding Eventlistener To Geturl After A Specific Flv Is Finnish Playing
my evenlistener is able to get a url after my video player finish playing
but i need it to be specific after the dvd.flv video finish the function is executed please see coding below, i would appreciate some help






stop();
attachMovie("FLVPlayback", "myplayer", 1);
myplayer._x = 415;
myplayer._y = 203.1;
myplayer._width = 320;
myplayer._height = 240;
myplayer.autoPlay = true;
myplayer.activePlayControl = true;
myplayer.controllerPolicy = "on";
myplayer.totalTime = 0;
myplayer.bufferTime = 3;
myplayer.autoSize = true;
myplayer.skinAutoHide = false;
myplayer.maintainAspectRatio = true;
myplayer.volume = 110;
myplayer.playButton = playbtn;
myplayer.pauseButton = pausebtn;
myplayer.backButton = backbtn;
myplayer.muteButton = mutebtn;
myplayer.seekBar = seekbtn;
//myplayer.volumeBar = volumebtn;
//myplayer.bufferingBar = BufferBar;
myplayer.contentPath = "videos/dvd.flv";
video1_mc.onRelease = function() {
myplayer.contentPath = "videos/interview.flv";
};
video2_mc.onRelease = function() {
myplayer.contentPath = "videos/dvd.flv";
};
var displayListener:Object = new Object();
displayListener.complete = function() {
getURL("http://www.woolworths.co.uk/ww_p2/product/index.jhtml?pid=50787969");
};
myplayer.addEventListener("complete", displayListener);
video3_mc.onRelease = function() {
myplayer.contentPath = "videos/Demoreel.flv";
};

Adding EventListener MouseEvent Click To Existing Mc Which Aleady Has Alpha Motion...
hi, my name's jude and i'm an author designing a site for my new publishing company. i want to use a flash button on the site and am having problems finding the right actionscript. i'm a total nOOb in actionscript but i promise i've done lots of research into this - however the only tutes i can find are for starting from scratch making movie clip buttons.

all i want to do is add the actionscript for a mouse click which takes you to the desired URL, to this existing code controlling the motion of the movie clip.

onClipEvent(load)
{
dir = 0;
speed = 6;
original._alpha = 0
this.onRollOver = function()
{
dir = 1;
}

this.onRollOut = function()
{
dir = -1;
}
useHandCursor = true;
}
onClipEvent(enterFrame)
{
temp = original._alpha + speed*dir;
original._alpha = Math.min(100,Math.max(temp,0));
}

you can see the completed .swf (before i changed the HandCursor to true) here.

and here are screenshots of the relevant pages in flash

http://i250.photobucket.com/albums/g...reenshot-1.jpg

http://i250.photobucket.com/albums/g...reenshot-2.jpg

http://i250.photobucket.com/albums/g...in/scene-1.jpg


- i would be so grateful for any help from you guys (and, i presume, girls!) - many thanks in advance.

Adding Parameter In Certain Frame
How to manipulate position of movieclip in for eg. 12th frame? The movieclip has been given already a motion tween.
Couse I want to move a movie clip smoothly from one point to another (dependable from what I write in AS).

Adding Parameter To A Function
hi :O)

i've got 32 different movieClips on my stage and 32 pictures, all
pictures with _alpha = 0.

my movieClips are named:

billedevalg01_mc
billedevalg02_mc
....
billedevalg32_mc


and my pictures are named:

billede01_mc
billede02_mc
....
billede32_mc


i've made my file so that my movieClip: billedevalg01_mc can make
movieClip: billede01_mc visible and invisible this way:


ActionScript Code:
this.billedevalg01_mc.onRollOver = visBillede;
this.billedevalg01_mc.onRollOut = skjulBillede;
 
var hvilketBillede:Number;
function visBillede() {
billede01_mc.alphaTo(100, 0.6, "linear");
}
 
function skjulBillede() {
billede01_mc.alphaTo(0, 0.6, "linear");
}


this works perfectly, but now i'd like to add a parameter to my
function, so I can use the two functions visBillede and skjulBillede
to make every picture on stage visible and invisible..

i've tried the following, but it doesn't work.


ActionScript Code:
this.billedevalg01_mc.onRollOver = function() {
visBillede(01);
}
 
this.billedevalg01_mc.onRollOut = function() {
skjulBillede(01);
}
 
var hvilketBillede:String;
function visBillede(hvilketBillede){
_root["billede"+hvilketBillede+"_mc"].alphaTo(100, 0.6, "linear");
}
 
function skjulBillede(hvilketBillede){
_root["billede"+hvilketBillede+"_mc"].alphaTo(0, 0.6, "linear");
//billede01_mc.alphaTo(0, 0.6, "linear");
}


i hope you understand what i mean... can anyone help me out?

thanks
felisan

Adding Parameter To Button Click
I have read a few threads the subject of custom Events, dispatchEvent, and various related areas, but I'm still a little confused.

I have a button, and when I press that button, I want a function to run, with parameters. So I have this:


ActionScript Code:
formButton.addEventListener(MouseEvent.CLICK, submitPressed);

...but I can't send any parameters to submitPressed this way. So, I'm trying to extend the MouseEvent Class:


ActionScript Code:
package classes
{
    import flash.events.MouseEvent;
   
    public class CustomEvent extends MouseEvent
    {
        public var dataObj:Object;
        public function CustomEvent(type:String, evObj:Object)
        {
            super(type);
            dataObj = evObj;
        }
    }
}

Is this right so far? I saw this in another thread. It pretty much makes sense to me...

So then:

ActionScript Code:
var newSeriesObj:Object = new Object();
newSeriesObj.whichNum = 4;
var myCustomEvent:CustomEvent = new CustomEvent(MouseEvent.CLICK, newSeriesObj);
formButton.addEventListener(/*what goes here?*/, eventSubmit);

I know that MouseEvent.CLICK can't go in there anymore, because I have the eventSubmit function with a CustomEvent parameter. I also know that the first parameter to addEventListener must be a String indicating the event type.

I feel like I'm very close to understanding this - can someone fill in the blanks for me please?

Adding Function Parameter To Incrementor For Movieclip Name
I am using the following code:

note.drawpoints = function(pointType:String) {
for(x=0; x < 16; x++) {
duplicateMovieClip('point_mc', 'point'+x, 30+x);
_root['point'+x]._name = pointType + x; <-- problem is here
trace(_root['point'+x]._name);
}
}

I'm calling the function like this:
note.drawpoints('highhat');

When I trace the movieclip name, I got undefined. Why is this?

EventListener Help
Can someone explain how I can create an event listener to determine wether the mouse is pressed down on a movie clip?

Thanks
Mike

EventListener
Hi,

Can any expert explain about the usage of Event Listener in a way that people can understand easily? An analogy might be very helpful. Thanks!

Can This Be Done With An EventListener?
Dear All,

I have created a Movieclip called box_mc0. which appears on the stage as a blue rectangle.
I have attached the onRelease method to it so that when the mouse moves over it I can in principle click it. However, what I would like to do is create an event so that when the mouse is clicked over the MC, trace appears with the MC name, box_mc0.
Can this be done?
I welcome any advice

Thanks in advance


Code:
this.createEmptyMovieClip ("box_mc0", 1);
box_mc0._x = 200;
box_mc0._y = 200;
with (box_mc0)
{
lineStyle (1, 0xCCCCCC);
beginFill (0x0033FF);
moveTo (0, 0);
lineTo (50, 0);
lineTo (50, 20);
lineTo (0, 20);
lineTo (0, 0);
endFill ();
}
//var box_mc0:MovieClip = new MovieClip;
var listener:Object;
listener = new Object ();
listener.click = function (evtObj)
{
trace ("The " + evtObj.target.label + " cell was clicked");
};
box_mc0.addEventListener ("click", listener);

box_mc0.onRelease = function ()
{
// I know this function does not do anything other than allow the MC to be clicked by the mouse
};

EventListener...: From AS2 To AS3..?
I'm trying to rewrite som AS2 code so it will fit to AS3 but some minor problem occurs...

Here's the AS2 code:

panel.onRollOver = panelOver;

function panelOver() {
this.onEnterFrame = scrollPanel;
delete this.onRollOver;
}

The idea here is to create an EventListener in AS3 that will trigger when the pointer is rolling over the movieclip "panel".
So far, so good...

Here's the AS3 code so far:

panel.addEventListener(MouseEvent.MOUSE_OVER, panelOver);

function panelOver(myEvent:MouseEvent):void {
this.onEnterFrame = scrollPanel;
}


Now, the problem is to rewrite [delete this.onRollOver;] so it will work in AS3...

Could it be something like:
delete this.EventListener(panel)?

I'm really struggling these days finding my way through AS3 but I do feel that I'm starting to get a hang of it...

Thank you for any help I get...!

PS.
I think I might run into some more problems after solving this one.. But we're all here to learn, aren't we?

EventListener
Hello i am really new to action script this is my first attempt and im really stuck!
I am creating a picture gallerey and have the following code on the thumbnail images to fade the images on mouse over but I am stuck on making it a button. Ive have tried the second piece of code I have attached but it dosnt work could any one point me in the right direction.
thanks
dan







Attach Code

thumb1_btn.addEventListener(MouseEvent.MOUSE_OVER,onRoll);

function onRoll(event:MouseEvent):void
{
thumb1_btn.alpha = 1;
trace("fade")
}

thumb1_btn.addEventListener(MouseEvent.MOUSE_OUT,onRollO);

function onRollO(event:MouseEvent):void
{
thumb1_btn.alpha = .5;
trace("fade1")
}


thumb1_btn.addEventListener(MouseEvent.MOUSE_UP,onClick);

function onClick (event:MouseEvent):void
{
photosmc.gotoAndPlay("image1");
}

EventListener
Hi, why dosent my eventlistener on the combobox work?


Code:

import mx.controls.*;
import mx.utils.Delegate;
import mx.events.EventDispatcher;

class no.pd.FileBrowser
{


// Event Listner
private var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;


// View
private var holder_mc:MovieClip;
private var container_mc:MovieClip;
private var fileview:MovieClip;
private var viewcombo:ComboBox;
private var viewlist:MovieClip;
private var item_mc:MovieClip;
private var item_arr:Array;



/**
* FileBrowser : Constructor
*/

public function FileBrowser(target:MovieClip)
{
EventDispatcher.initialize(this);
container_mc = target;
initView();
}


/**
* initView : Set the view
*/

private function initView()
{
holder_mc = container_mc.attachMovie("filebrowser_mc", "filebrowser_mc", 1);
fileview = holder_mc.fileview;
viewcombo = holder_mc.viewcombo;
viewlist = holder_mc.viewlist.content1;
item_arr = new Array();

// Event Listenters
viewcombo.addEventListener("change", Delegate.create(this, onViewComboChange));
viewcombo.addEventListener("close", Delegate.create(this, onViewComboClose));
}

private function onViewComboChange(evtObj:Object)
{
trace ("onViewComboChange");
}

private function onViewComboClose(evtObj:Object)
{
trace ("onViewComboChange");
}

}

EventListener
Hello

I have at the moment lame code like:

frame 1
if (nameObject != null){doSth(); stop();}

frame 2
gotoAndPlay(1);

I need better form of checking if my object get data.
So if somebody know how use events or similar efects on objects and will help I will be happy.(In real i'm using Timer [in-time-delayed/repeated-function], but its same, just without frames)

Thanx a lot

EventListener
Hello

I have the following simple action script file xmlLoader.as
It has on XML variable and its constructor takes as an argument a string
wich represents the path for the xml file so it defines a URLLoader loads the xml file and stores the data on the XML variable.
I have realized that the eventlistener function onloadXml it does not executed.



Thank you

package {

import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;


public class xmlLoader {

private var xml:XML;

public function xmlLoader(xmlDocument:String):void {

var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE, onloadXml);
loader.load(new URLRequest(xmlDocument));
}

public function onloadXml(e:Event):void {
this.xml = new XML(e.target.data);

}

public function getXML():XML {
return this.xml;
}
}
}


import xmlLoader;
import flash.events.TimerEvent;

var path:String = "images.xml";
var myLoader = new xmlLoader(path);
var xml = myLoader.getXML();
trace(xml); //// null ??????

Resetting An EventListener
I've got an addEventListener attached to a mediaPlayback component and it needs to be reset so that the video that is being played can play again when the user goes back to it.

I am using cuepoints for the eventListener and everytime I return to the video after it has reached it's cue point nothing plays the second time around.

Here is the code I am using:


player1.removeAllCuePoints();
player1.addCuePoint("part2",23);

myObj=new Object();

myObj.cuePoint=function(p){
stopAllSounds();
gotoAndPlay("part2");
}

player1.addEventListener("cuePoint", myObj);



Player1 is the instance name of the MediaPlayback component.

Help would be greatly appreciated.

EventListener Problem
ok, I have a list box.. I am trying to make it, on selection of an item, load the data of that selection into a movie clip.

Example.

listItem 1 = cards/trans_1.jpg
listLabel 1 = Transportation Image 1

When I select label 1, I want it to load "cards/trans_1.jpg" into a movieclip called loadCardMain.

When I trace the data, I get the correct label, but the data is (object Object)


Here is my code.. please see if you find anything wrong with it.

_________________________________________________

cardListener = new Object();
cardListener.change = function(eventObj)
{
var eventSource = eventObj.target;

var theSelectedCard = eventSource.selectedItem;
var theSelectedCardLabel = theSelectedCard.label;

loadMovie(theSelectedCard,"this.loadCardMain");
trace ( "You selected "+theSelectedCardLabel+".");
trace ( "You selected "+theSelectedCard+".");
}
cardList.addEventListener ("change", cardListener);

_________________________________________________

EventListener Problem
ok, I have a list box.. I am trying to make it, on selection of an item, load the data of that selection into a movie clip.

Example.

listItem 1 = cards/trans_1.jpg
listLabel 1 = Transportation Image 1

When I select label 1, I want it to load "cards/trans_1.jpg" into a movieclip called loadCardMain.

When I trace the data, I get the correct label, but the data is (object Object)


Here is my code.. please see if you find anything wrong with it.

_________________________________________________

cardListener = new Object();
cardListener.change = function(eventObj)
{
var eventSource = eventObj.target;

var theSelectedCard = eventSource.selectedItem;
var theSelectedCardLabel = theSelectedCard.label;

loadMovie(theSelectedCard,"this.loadCardMain");
trace ( "You selected "+theSelectedCardLabel+".");
trace ( "You selected "+theSelectedCard+".");
}
cardList.addEventListener ("change", cardListener);

_________________________________________________

Problems With EventListener
I have a audioControl_mc that in the end of the frame it has a dispatch event.


Quote:




this.dispatchEvent(new Event("FINISH"));




Then on the main timeline I have a eventlistener


Quote:




audioControl_mc.addEventListener("FINISH",onAudioF inish);

function onAudioFinish(event:Event):void {

}




but for some reason the event listener isn't comming out with anything.

EventListener Question
What I want to do here is create a target and have it move across the screen for a few seconds, and after the time is up remove it. So what i would like is either to have the eventListener return a boolean or have it pass the mc to the removeTarget function.

From what I read it seems like the only way to do this is to create a custom event then? is there any other way that I am missing?



Code:
function createTarget() :void
{
var timeT=4; //how many seconds for the tween
//new target mc
var targeta:Targeta = new Targeta();
target_mc.addChild(targeta);
targeta.x=0;
targeta.y=(Math.random()*375)+25;
//moving the target across the screen in timeT seconds
var myTween:Tween = new Tween(targeta, "x", None.easeOut, 0, 600, timeT, true);
//now i want to remove the mc after it finishes
var timer2:Timer = new Timer(timeT*1000, 1);
timer2.addEventListener(TimerEvent.TIMER, removeTarget);
timer2.start();
}
function removeTarget(evt:TimerEvent) :void
{
target_mc.removeChild();

}

[F8] Eventlistener Not Working?
On my page I have a button instance named "loadBtn", and I want to add an eventlistener in order to browse for a file locally which Flash should read (a txt file). But for some reason nothing happens when I run the following code?


Code:
import flash.FileReference;
import flash.events.*;

myListener = new Object();
myListener.click = function(evt){
var fr:FileReference = new flash.net.FileReference();
fr.browse();
}

loadBtn.addEventListener("click", myListener);
Would be gratefull for any help on loading/saving a file locally.

Cheers.

Eventlistener Confusion
Hi

I've been going on okay-ish with the whole as3 project but I'm afraid I'm a bit clueless as to what I should do here.
I have three buttons, I want to give each one a over and clicked state but I'm not exactly sure how to go about it.

I don't know how I should do this, every button has an eventListener but how do I assign each one different functions?
I get errors if I take away the comments and can't think of another way to do this (I know the way it is now is wrong).

this is the code I have so far...

Code:
package
{
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import caurina.transitions.*;

public class main extends Sprite
{
public static var origW:Number = 1024 //original stage width
public static var origH:Number = 768 //original stage height

//graphic resources
private var bg:Sprite;
private var cont:Sprite;
private var art:Sprite;
private var photo:Sprite;
private var project:Sprite;

//constructor
public function main ()
{
//Tel the player not to scale the assets
stage.scaleMode = StageScaleMode.NO_SCALE;

//Tell the player to put co-ords 0,0 to the top left corner
stage.align = StageAlign.TOP_LEFT;

//Listen for resize events
stage.addEventListener(Event.RESIZE, onResize);

//Create and add body resource to the display list
bg = new bg_mc();
addChild(bg);

cont = new content();
addChild(cont);

art = new art_mc();
cont.addChild(art);
art.x = 168.1;
art.y = 522.7;

photo = new photo_mc();
cont.addChild(photo);
photo.x = 136.1;
photo.y = 517.9;

project = new project_mc();
cont.addChild(project);
project.x = 74.2;
project.y = 532.5;

//Size everything after creation to insure the app is drawn
//properly the first time it is seen prior to any user initiated
//resizing
onResize(null);

art.addEventListener(MouseEvent.CLICK, ClickListener)
photo.addEventListener(MouseEvent.CLICK, ClickListener)
project.addEventListener(MouseEvent.CLICK, ClickListener)

function ClickListener(event:MouseEvent):void
{
trace("art button clicked")
var box:Sprite = new Sprite();
box.graphics.beginFill(0xffffff, 1);
box.graphics.drawRect(10, 600, 10, 10);
box.graphics.endFill();
cont.addChild(box);
}
//function clickListener(event:MouseEvent):void
//{
//trace("photo button clicked")
//}
//function clickListener(event:MouseEvent):void
//{
//trace("projects button clicked")
//}

}
//listening for stage resize
public function onResize(event:Event):void
{
//get the new stage height
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;

//then update the children with this new size
bg.height = sh;
bg.width = sw;
cont.height = sh;
cont.width = sw;
}
}
}


Thanx in advance

Tracking EventListener's
Hey all. Been toying around in CS3 as of late, and I am starting to like it a bit. I've been making extensive use of EventListeners on a project I'm working on. Thing is, debugging for CPU utilization is a pain in the rear. I'd like to know what you all do to track down listeners that may be problematic (i.e.: is there a utility in the debugger to monitor listeners, etc...?)

Thanks,
Dewman

If EventListener Exists...
i was wondering if there was a method to put in an if statement to check whether a particular event listener exists?

EventListener Not Working
I am at the last step of an involved project, and for some reason I can't get it to work. I have a function that loads an image into a target movieClip, and I want to call a function when that image is loaded. For some reason, the image loads fine, but the eventListener never triggers. the function:

Code:
_global.changePage = function(newpage) {
var thumbListener = new Object();
thumbListener.complete = function(evt) {
showDescription();
}
thumbPath =newpage+".jpg";
_root.contentbox.pic.unloadMovie();
_root.contentbox.pic.addEventListener("complete", thumbListener);
_root.contentbox.pic.loadMovie(thumbPath);
};
I thought it was a matter of scope, but I tried calling the listener Object from the root and globally and neither work.

Slow Eventlistener
Hello,

I'm making a menu generated from xml. Everything has been working fine, at least during the developement, but when I test it in a browser, the buttons doesn't work correctly, you have to press them several times before flash does anything..

Does anybody got a clue what this can be?

Link to swf

How To Remove Eventlistener?
I have a movieclip on frame 2 of the main timeline that I want to fade alpha to 0, once the alpha is less than .1, I want the root to gotoandstop frame 1 where the main menu is. I added eventlistener with if statement, how do I remove the eventlistener? I just read that if you dont remove eventlisteners...memory problems could exist. Here is what I tried, but not sure if it removes it:


Code:
blur_mc.addEventListener(Event.ENTER_FRAME, exitSection);

function exitSection(event:Event):void {
if (blur_mc.alpha < .1) {
blur_mc.removeEventListener(Event.ENTER_FRAME, exitSection);
root.gotoAndStop(1);
}
}
Would this remove the eventlistener from my blur_mc?

EventListener Question
So, I've trolled the net for about an hour now trying to figure this out, and it's definitely one of those "I'm sure there's a way, but I don't know what it is" scenarios -

I have the code:


Code:
b1pic.addEventListener(MouseEvent.MOUSE_OVER, goPics)
which works wonderfully, but what I'm wondering is - is there a way, once the function goPics is called, is there a way to obtain the object that called it? So, once goPics fires, how can I get that b1pic called it?

is there a native way to do this? or even a way to pass a variable with the function when its called by the EventListener? I guess, the equivalent of calling goPics(b1pic)?

any help would be mucho appreciated!

Help Removing Eventlistener
Hello,

I am creating a scene with a torch attached to the mouse. I only want it to be available in this scene, and when I click to change to a different scene, it gives me the error "TypeError: Error #1009: Cannot access a property or method of a null object reference.at tomb_fla::MainTimeline/moveTorch()"

//Create torch
var torch:Sprite = new Sprite();
var exitCheck:Boolean = true;

mcDarkBackground.addChild(torch);
torch.graphics.lineStyle(1,0x000000);
torch.graphics.beginFill(0x0000FF);
torch.graphics.drawCircle(0,0,85);
torch.graphics.endFill();

//Mask light background to see dark background
mcLightBackground.mask=torch;

//Add listener for mouse movement and get torch to follow
stage.addEventListener(Event.ENTER_FRAME, moveTorch);

function moveTorch(Event):void {
exitCheck = true;
torch.x = mcLightBackground.mouseX;
torch.y = mcLightBackground.mouseY;
}

if (exitCheck = false)
{
stage.removeEventListener(Event.ENTER_FRAME, moveTorch);
}

Currently the boolean "exitCheck" is set to true when each of the buttons are clicked.

Can anyone help with this? I'm really baffled!

Thanks!

EventListener Not Working?
Is this valid? If so, why doesn't it work?


ActionScript Code:
addEventListener(dudeel.onRelease,goToSite);
function goToSite(){
    navigateToURL("http://dudeel.com", "_blank");
}

Movieclip Eventlistener
First sorry for my English.

I want to addchild on the stage, it is a movieclip (animation with a few frames).

When I add it to the stage, it play. I want when movieclip is over (at last frame) to remove this child.

What eventlistener must I use?

function showSmile():void
{
var smile:sprite58 = new sprite58();
smile.x = 175;
smile.y = 72;
stage.addChild(smile);
}

function hideSmile():void
{
stage.removeChild(smile);
}

EventListener And Dispatcher Again
Ok I have 3 classes as an example. Main.as
AutoSlide.as
ControlPac

Main looks like this.

Code:

package com {

import flash.display.Sprite;
import flash.events.Event;
import com.slideshow.AutoSlide;
import com.ControlPac;

public class Main extends Sprite{

private var _autoSlide : AutoSlide;


public function Main(){
setUpClasses()
}



private function setUpClasses() : void {

_autoSlide = new AutoSlide(_appData.xmlData.member.length() );
_autoSlide.start();

var controlPac = new ControlPac( );
controlPac.addEventListener(AutoSlide.CALL_SLIDE, callNextSlide);


}

private function callNextSlide( evt : Event ) : void {
trace("EVT WORKING");
}



}
}

AutoSlide looks like this.


Code:
package com.slideshow {

import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.EventDispatcher;
import flash.events.Event;

public class AutoSlide extends EventDispatcher {

private var slideCount : Number = 0;
private var timer : Timer;
private var maxSlide : Number;
public static const CALL_SLIDE:String = "call_slide";

public function AutoSlide( maxSlide : Number ) {
this.maxSlide = maxSlide;
}


public function start() : void {
timer = new Timer(3000 );
timer.addEventListener(TimerEvent.TIMER, onCallSlide );
timer.start();
}

public function stop() : void {
timer.stop();
}

private function onCallSlide( evt : TimerEvent ) : void {
dispatchEvent(new Event(AutoSlide.CALL_SLIDE ) );
}


}
}
ControlPac looks like this.


Code:

package com{

import flash.events.Event;

public class ControlPac {

public function ControlPac() {


}

private function callNextSlide( evt : Event ) : void {
trace("IM JUST GOT AN ALERT");
}

}

}
I understand that I can listen for the dispatched event if my target is the class that is dispatching the event.


Code:
_autoSlide.addEventListener(AutoSlide.CALL_SLIDE, callNextSlide);

private function callNextSlide( evt : Event ) : void {
trace("EVT WORKING");
}
But I also though other objects could be setup to listen for an event that has been dispatched. This is why I put a listener on ControlPac

Code:
controlPac.addEventListener(AutoSlide.CALL_SLIDE, callNextSlide);
But its not hearing the dispatched event. I tried to extend ControlPac as an evnt and also as a Sprite but its still not able to receive dispatched events from another object. Any ideas why and am I completely lost here.

Hi How Do I Use The Same EventListener In A Frame More Than Once?
Hi!!
Long time no see. I've apparently ran into a problem using eventListeners and frames.
Anyways, I'm using Flash CS3 and ActionScript 3.0 and I'm making a game menu where the arrow is supposed to go down when you press the down key on your computer. This is the code I used on the first frame:

ActionScript Code:
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, downHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, upHandler);

function downHandler(event:KeyboardEvent):void {
    if (event.keyCode == Keyboard.DOWN) {
        gotoAndStop(2);
    }
}

function upHandler(event:KeyboardEvent):void {
    if (event.keyCode == Keyboard.UP) {
        gotoAndStop(5);
    }
}

Anyways, I tested it, and it goes to Frames 1-5, but it only works once, up or down. Is there any way where I can use the same functions on ActionScript more than once??

Any help is greatly appreciated.

EventListener Problem
Hello,
This is example from tutorial, but i can`t make it to process 13 line, unless i delete 9-11 lines, but then listener is skipped, thats bad, couse all photos are showed one by one without waiting... my button is named: `next`. working with Flash CS3 ActionScript 2.

1. var x = 1;
2. _root.createEmptyMovieClip("MyImagesHolder", 0);
3. var MyArray = new Array();
4. var i = 0;
5. while (i<=NumberOfImages) {
6. MyArray = LocationToImages+i+FileType;
7. i++;
8. }

9. NextListener = new Object();
10. next.addEventListener("click", NextListener); //!!!!
// Call the code below if the next button is clicked
11. NextListener.click = function() {
12. x = x+1;
13. loadMovie(MyArray[x], _root.MyImagesHolder);
14. }
15. stop();

Mainly i want to do something like 9 small pictures, and then i click on one of them, on the right to them opens big one. on this example it should work only with button, not pusshing the photo, and it is not i want, but i want to understand, what is wrong with my example above.
so, if someone could correct an error + get an example or link to tutorial, how to make every photo be iteractive, if clicked, on the right opens big one...
now photos are as graphic, not converted to symbols, and i don`t know if it`s worth to do so...
ok, thanx, and forgive for my spelling ;]

How Can I Get EventListener To Trace? Thx
Hello Everyone,

I have been trying to learn the eventListeners and cannot spot what am I doing
wrong. I just want a listener to pop a trace when user clicks on a movieclip_mc.
Appreciate all your help.









Attach Code

var myListener:Object = new Object();
myListener.onPress = function(){
trace("You got me!");
}
movieclip_mc.addListener(myListener);

Call EventListener
Hi,
I have several checkboxes. To each CB I have added an EventListener on click.
But now, when data comes in I make 1 CB to >selected = true<.
Can I also call the click function so the CB acts as it would be clicked?

var sub1Listener:Object = new Object();
sub1Listener.click = function(evt:Object){
if(evt.target.selected == false){
//do nothing
}else if
(evt.target.selected == true){
//do some..
}
};
this._parent.holderSub_mc["sub1_cb"+a].addEventListener("click",sub1Listener);

Many thanks,
Luciewong

Add A Param To An EventListener, Is That Possible?
Hi , does anyone know if it's possible to add a param to an EventListener?

for example i have an timer.

myTimer= new Timer(500, 3);
myTimer.addEventListener("timer", createSquare);
myTimer.start();

I would like to pass the current movie to my EventListener like this or add some more params.

myTimer.addEventListener("timer", createSquare(currentMovie, maximum));

Is this possible ?

AS3 EventListener Question
So, here's what I am trying to do in AS3.

1. The main timeline is stopped. I load an XML file.
2. I use an eventListener to determine when the XML file has finished loading.
3. At that point I run a function that loops through the XML data and loads 37 different jpegs (which are identified in the XML file) onto the page.

I'm good so far. What I can't figure out how to do is to tell the main timeline to begin playing once all of the jpegs have been loaded. Can I create another eventListener that listens for when the function is done and all the jpegs have been loaded? I can't seem to wrap my head around how I would do that. Any advice or direction would be greatly appreciated. Thank you very much!

EventListener For Sounds
The following creates a new sound and instantly plays. I want to make a button visible when the song ends, but the following will not work. Any ideas! Thanks.

var sndA:Sound = new theme();
sndA.play();

sndA.addEventListener(Event.COMPLETE, endSound);
function endSound (evt:Event):void {
envelopebut.visible = true;
}

Listener VS. EventListener
Hi Guys

I was conducting some experioments on the Combo box component.

So I was using addEventListener("change",myListener) and it was working fine, then I thought of trying addListener instead, but then it didn't work. This lead me to google search what addListener does.

Anyway, I saw some stuff that made me conclude that there is a "listener" and there is an "event" and there's a difference between them. The Key object as 2 listeners: onKeyUp and onKeyDown , but none of the components have listeners, they just have events.

So I wanted to know why, and whats the difference between a listener and an event, and the difference between addListener and addEventListener.

Thanks dudes!!!

EventListener Question...?
Hello all,

Is it possible to add an Event Listener to a target within a different class?
I have tried about everything I could think of - but no luck...

EventListener And Performance
History:
Iīve a class, in my application, that generates different layout interfaces depending on what to do. Every interface contains a number of event listeners for buttons etc. The maximum numbers of interfaces is between 4-5.

Whatīs better:
1. Turn on/off the different interfaces by the visible=true/false property and donīt remove any event listers.

2. Turn off the different interfaces using removeChild() and then remove all listeners. When turning on you creates the interfaces again.


Every event listener use memory but creating the interface everytime also have some affects (/CPU).

Combobox Add EventListener
hello there,

i'm trying to add some action to the combo box i grabbed from the components on Flash CS3.

here is the code that i have so far


ActionScript Code:
import fl.data.DataProvider;import fl.events.ComponentEvent;var items:Array = [{label:"Arizona", data:"87.97"},{label:"Colorado", data:"91.97"},{label:"Iowa", data:"91.97"},{label:"Idaho", data:"91.97"},{label:"North Dakota", data:"91.97"},{label:"New Mexico", data:"91.97"},{label:"South Dakota", data:"91.97"},{label:"Wyoming", data:"91.97"},{label:"Minnessota", data:"91.97"},{label:"Montana", data:"87.97"},{label:"Nebraska", data:"87.97"},{label:"Oregon", data:"87.97"},{label:"Utah", data:"87.97"},{label:"Minnessota", data:"87.97"},{label:"Washington", data:"91.97"},];aCb.dataProvider = new DataProvider(items); aCb.addEventListener(ComponentEvent.ENTER, onAddItem);  function onAddItem(event:ComponentEvent):void {    var newRow:int = 0;    if (event.target.text == "Add") {        newRow = event.target.length + 1;         event.target.addItemAt({label:"screen" + newRow, data:"screenData" + newRow},             event.target.length);     }}


the combo box instance name is aCb and i have a dynamic text called priceText, so i would like to select a state from the array list and my data to be shown on the dynamic text. any help with this please. thank you!

Arguments To EventListener?
I have xml with button list info, name and link


Code:

<?xml version="1.0" encoding="utf-8"?>
<menulist>
<menuitem main="true" >
<itemname>home</itemname>
<link>test1.swf</link>
</menuitem>
<menuitem>
<itemname>about</itemname>
<link>test2.swf</link>
</menuitem>
</menulist>
I've managed to generate a list with buttons. Using a for loop. While generating them I'm also adding an eventlistener


Code:

for each(var value:XML in myXML.menuitem) {
obj[j] = new listmenuitem();
menucontainer.addChild(obj[j]);
obj[j].y = j*itemheight;
obj[j].button.addEventListener(MouseEvent.CLICK, onClick);
j++;
}
which nicely performs it. At this moment however the onclick function uses one link only...


Code:

public var externalswf:URLRequest;
public var dolink:String = "http://www.somedomain.com";

public function onClick(event:MouseEvent):void{
externalswf = new URLRequest(dolink);
navigateToURL(externalswf, "_top");
}
Is there a way to pass the xml value to the function, sort of like "delegate"?
Or an eays alernative?

P.

Getting Object Name From Eventlistener
hi i have currently have this frustrating problem that might be very simple but i dont get it to work for me


Code:
//square is a object that is in a array
while (i < 25) {

square[i].addEventListener(MouseEvent.CLICK,clicker);
i++
}


function clicker (evt:MouseEvent):void {

//i would like the the trace to output the specific array number from the the object that
//was being clicked for example the trace would output: 23

trace(evt);

//but instead i get this [MouseEvent type="click" bubbles=true cancelable=false
//eventPhase=3 localX=123.35 localY=126.7 stageX=585.8 stageY=519.05
//relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0]


}

EventListener On A Flv Not Workin'
Hey guys,
I want to add a simple "play again" button when my FLV stops playing. Pretty simple, right? For whatever reason I can't add an eventListener when my video stops though. I can't even trace anything. the video loads i can dynamically change the volume so it's not like i'm referencing it wrong or something like that. Any ideas?


Code:
//stop swf playback
stop();
import mx.video.*;
//load .flv
_root.myFlv.contentPath = "../iron.flv";

//new listener to show "play again" btn
var listenerObject:Object = new Object();
_root.myFlv.addEventListener("complete", listenerObject);
listenerObject.complete = function(eventObject:Object):Void {
replayBtn._alpha = 100;
};

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