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




Listeners And Broadcaster



Hi all!

I need need help on the following.....:

I want to make a color silder to change the color of my nav-items. The nav-items are generated dynamicly from an xml document. I should be able to do this by writing a function on the color slider that checks how many nav-items there are and then change the color. but....

What i would really like to is use a serious AS 2.0 method to do this, using listeners and broadcasters. Now i've went through the LiveDocs and tutorials, but i just can't seem to figure it out. I need all my nav items to listen to one object (the slider) but I can't add a listener in a class which i've given those Nav-items(?)......

As you can read... I'm pretty confused!!

If there's someone who could show me (and preferrably explain) how I could have all my dynamic mc's listen to one object, so that I would have to code only the slider and nothing else.... That would be, like, so totally appreciated (no, really!!)

thanks in advance for any pointers!

patrick



Ultrashock Forums > Flash > Flash Newbie
Posted on: 2005-03-12


View Complete Forum Thread with Replies

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

AS2: Broadcaster / Listeners In OOP? (class / Class)
I want to know how to make class instances into listeners and broadcasters, from inside each class. Here is what I am trying specifically...

part of the Proj class... (projectiles, as a matter of fact)

Code:
private function listen():Void {
u.register(this);
onUpdate = function(){
step(); // a function I have which makes the projectile move (not shown)
}
}
where "u" is another class, the Updater class with this code...


Code:
class Updater {

// const. --- make this a broadcaster
public function Updater(){
AsBroadcaster.initialize(this);
}

// function to add a projectile as a listener
// (in this case, called by projectiles)
public function register( p:Proj ):Void {
addListener( p );
}

// update all projectiles listening to the updater
public function updateListeners():Void {
broadcastMessage("onUpdate");
}
}
Problem is, I get a bunch of errors:

There is no method with the name 'addListener'.
addListener( p );

There is no method with the name 'broadcastMessage'.
broadcastMessage("onUpdate");

There is no property with the name 'onUpdate'.
onUpdate = function(){

Thanks in advance!

PS: What is the syntax for using AS2 code tags instead of just "[CODE|"?

AS3 Broadcaster
I haven't touched Flash in a while but I have a site to do so my "skills" need some brushing up on. A while ago, I created a class that registers classes and dispatches events to them and they would react accordingly. It was my alternative to the AS2 Broadcaster class. I've seen some other alternatives out there but mine works fine. However, I was wondering if there was an overall better alternative to this dispatching method or if my class can be cleaned up at all?

Also, can someone please direct me to or suggest a good environment for creating typical OOP sites and classes. i.e -->

MainCode.as
loading/
- Loader.as
shell/
- Display.as
model/
- Model.as


Model Class

ActionScript Code:
package model {    import flash.events.Event;    import flash.events.ProgressEvent;    import flash.events.EventDispatcher;    import flash.net.URLLoader;    import flash.net.URLRequest;        public class Model extends EventDispatcher {                static var xml:XML;        static var xmlLoader:URLLoader;                function Model(){}                // event dispatch methods                 static var dispatcher:EventDispatcher;                static var aListeners:Array;                public static function setDispatcher():void        {            dispatcher = new EventDispatcher();            aListeners = new Array();        }                public static function addListener(o:Object):void        {            aListeners.push(o);        }                public static function sendUpdate(s:String):void        {            for(var i:uint = 0; i<aListeners.length; i++)            {                aListeners[i].dispatchEvent(new Event(s));            }        }                                // xml methods                 public static function loadXML():void        {            xmlLoader = new URLLoader(new URLRequest("xml/siteData.xml"));            xmlLoader.addEventListener(Event.COMPLETE, xmlComplete);        }                static function xmlProgress(e:ProgressEvent):void        {            //trace("xml loading");        }                static function xmlComplete(e:Event):void        {            xml = new XML(e.target.data);            xml.ignoreWhitespace = true;            sendUpdate("xmlDone");        }                public static function XMLNodeByName(s:String, attribute:String):Array        {            var arr:Array = new Array();            for(var i:uint = 0; i<xml.child(s).length(); i++)            {                arr.push(xml.child(i)["@" + attribute]);            }                        return arr;        }                public static function XMLNodeByNum(num:Number):Array        {            var arr:Array = new Array();            for(var i:uint = 0; i<xml.child(num).children().length(); i++)            {                arr.push({name:xml.child(num).child(i).@name, data:xml.child(num).child(i)});            }                        return arr;        }                            }    }


example of usage:

ActionScript Code:
var oShell:Shell;...var mShell:MovieClip = new MovieClip();mClip.addChild(mShell);oShell = new Shell(mShell);Model.addListener(oShell);


in Shell class there would be:

ActionScript Code:
addEventListener("update", eventHandler);addEventListener("xmlDone", eventHandler);

Listener Or Broadcaster
I have a menu class that extends the MovieClip class. I want away to be able to listen from other movieclips or objects throughout the site to when a button in that menu has been pressed. I also want to be able to pass along the name of the button that has been pressed to the clips that are listening.

How can I do this?
I confused with listener and eventListener

Thanks

AS Broadcaster Problems
hey guys,
im having an issue with as broadcasting.

i have 4 unique movie clips.

the first thing my script dose is randomly choose one of the four and using the .attachMoveiClip method to duplicate it, this happens about 40times. Each movie clip is given a unique name.

what i want to achieve iswhen i click on any movie clip, it performs the same function.

i tried initializing each movie clip as it was created and add the same object as a listener to all.

then got the movie clips to broadcast "onClick" when onMouseDown.

then used
ActionScript Code:
obj.onClick = function{ trace("i got clicked"); }


this worked, except that when i click on movie clip, every movie clip sent the broadcat and i got the trace 40times.

is there a better way? or am i using this the wrong way to achieve what i want?

thx guys

New Broadcaster Problem
Hello everyone

As far as I can tell there is definately a bug using ASBroadcaster.

If you use either a) ASBroadcaster in a grandchild+ movieclip or b) add a listener at a later stage in the program.

When I do either of the above and try to transmit 3 variables, (source, StateA, stateB) it does not transmit the the second variable (or it doesn't get recieved)

I have checked rechecked the code, rewritten the code, produced a new file and re-wrote and still the same bug.

Before I forget , the broadcaster is initiated during a evaluation of a reciever of another broadcast. I.E. MovieClipA sends a broadcast message to MovieClip B, MovieClip B evaluates broadcast and invokes an object inside it to Broadcast to MovieClip C

I belive the code is right as I've created a class object 4 it and it runs fine within the parent or child clip but not any further, is there a workaround? can anyone help?

I'm desparate to get it 2 work since I need it for a presentation nextweek

zen

Broadcaster Continued
Last edited by in2mind : 2004-02-22 at 13:25.
























when i Asked about where AsBroadcaster went. I was told 'here's a simple answer:'


class MyClass {
var initialize:Function;
var broadcastMessage:Function;
var addListener:Function;
var removeListener:Function;

function MyClass () {
AsBroadcaster.initialize(this);
}
}


Where does this code go?
And once it's there, how is it implemented in your project?
Is it already included with installation??
If the answer is "just put it with the rest of your classes" There's apparently two places for classes (and many other documents): in FirstRun and in ApplicationSupport/Configuration/classes. Please specify if every class needs to reside in both of those folders.

If it's already sitting somewhere, ready to be used, how do you implement it?




________________________________________________________

Broadcaster/listener
Is it possible to have a broadcaster/listener relationship outside an individual movieclip??
I'm trying to attach a listener function onto an INSTANCE of a movie clip but the broadcaster is within another movieclip (in the original not instance). Both clips are in the root menu (atleast 4 now anyway) cannot seem to get the destinations right.

The Broadcaster is in a movieclip called line with name 'A' the Broadcaster object within this movie is called 'life', running a function 'onSpeak'.
The listener instance is called 'and1' with the its object listner called health.

can any1 help..please????

Using One Broadcaster Across Multiple Objects
I want to try and use one broadcasting object that several other objects will isten to, and I'm not quite sure how to set it up in my AS2 classes.

I know the first thing I would do is write a class that initialized itself with EventDispatcher, and then instantiate that class, but then how do I refer to that object from within the different classes?

Keeping Track Of Broadcaster
I am developing a webcasting app (realtime broadcast) using flash and asp.net. I would like to keep track of the online status(yes/no) of the broadcaster. I tried the following:

When broadcaster starts broadcasting:
On "Connect.Success", do a loadvars("setOnline.aspx?broadcasterid=111&online=yes") - setOnline.aspx would go update the database accordingly

When broadcaster signs off:
In the SERVER-SIDE SCRIPT, on application.onDisconnect, I tried to do similar loadvars procedure with online set to "no", but loadvars is no good in SSAS. I did try to do this in client side, but it dies too quickly before the loadvar code is executed.

I wonder if there is other way to accomplish the above tasks.(update a database column when broadcaster go online/offline through simply calling a aspx page with url parameters).
Thanks in advance,
Deepblue

EventDispatcher/Broadcaster In A Static Class
Hey everyone,

Afaik, you need to instantiate a class to assign a listener to them. That's what I do for normal classes. I use EventDispatcher.

However, there's this class I want to modify - it's used "staticly", much like the Tween class. To clear things up, the class I'm talking about is IntervalManager by kennybunch.com

I want to modify it because I want to be able to listen when a certain interval is complete - much like a tween's onMotionFinished, only I want an onIntervalFinished.

What do I need to do to add this to the class?

Question About Listener/Broadcaster Objects
I've recently been trying to wrap my head around the Listener Object (which had always seemed confusing to me). Tutorials made it's workings clear, but what they don't seem to touch upon is the WHY and WHEN of using it...

First, what I've read has said that "Your listener object can be any object, such as an existing object, movie clip, or button instance", but why would you want to use anything other than a Listener Object? Would it make sense syntactically to take a movie clip that you want to respond to a particular event , and add handlers and "addListener" it to the broadcasting object, or is there a reason that you would want to make a standalone Listener Object?


Also, are Listener Objects only intended for certain classes, such as MovieClipLoader, Selection, etc? Can a normal MovieClip be a broadcaster too?


And what is the MovieClipLoader class specifically? Does it "exist" on the stage, or is it just an intermediary that then uses a MovieClip? Does it HAVE to be used with the listener object? MovieClips have onLoad() and getBytesLoaded() functions as well...couldn't these be used just as easily to load external content?

The Broadcaster Class (AVANCED ONLY, Beginners Beware)
okay guys,

I'm not sure if anyone out there is familiar with the Friend's of Ed OOP for Flash 8 book... but inside those pages lies the classic class Broadcaster.

Broadcaster implements IEventDispatcher and together they act as an object that can store an array of events and listeners... so when a certain event occurs the Broadcaster object will look thru its array of registered events (strings) and when the event is found it will go thru a second array of listeners objects and their respective "mappedTo" functions that are to be called and possibly passed an "infoObj" of params.

The book later suggest that if you have a class that will be broadcasting events you may as well let that class extend Broadcaster.. That way you won't have to feed all your classes a reference to your Broadcaster object. When this class needs to dispatch and event is simple needs to say: this.super.dispatchEvent(event);

This sounds like a great solution for a movieclip button, but there is one very large problem. Let's say I have in my Library an animated movieclip button with the AS 2.0 linkage set to my "movieclipBtn" class. In this class I want to define many properties for this movieclip.. as well as event functions like .onPress();

In order to inherit such properties and methods my "movieclipBtn" class must extend MovieClip... and if it does this it cannot extend Broadcaster, because we all know that a class cannot extend more than one class at a time.

So.. what is a programer to do? Let the movieClipBtn class extend Movieclip and just send it a reference to the Broadcaster class? this would work... but i think it breaks the beauty of encapsulation a wee bit.

ideas?

Adding Listeners And Removing Listeners
Hi all,

I've come across a problem during the creation of a flash movie..

Basically the movie consists of two scenes. Key.LEFT moves from "help" scene to "interface" scene and numpad 9 goes to "help" from "interface".

It works fine from "help" to "interface" the Key.removelistener(helpListener) disables the Key.LEFT. But on going back to the "help" scene the Key.removeListener(interListener) doesn't disable numpad 9 enabling the user to jump to and from each scene with each press (code at bottom).

Is this usual behaviour? Does it have anything to do with help being the first scene and trying to remove something that hasn't been created yet?

Any work arounds or solutions to this problem would be greatly appreciated!!

Thanks in advance,

Ben Gazzard

Each scene;
----------------------------------------------------------------------
Help:

Key.removeListener(interListener);
helpListener = new Object();
helpListener.onKeyDown = function() {
if (key.LEFT) {
gotoAndPlay("Scene 1", 1);
}
};
Key.addListener(helpListener);
stop();

----------------------------------------------------------------------
Interface:

Key.removeListener(helpListener);
interListener = new Object();
interListener.onKeyDown = function() {
if (key.isdown(105)) {
gotoAndPlay("help", 1);
}
};
Key.addListener(interListener);
stop();

Listeners Unable To Listen To Other Listeners?
hi

i have a listener problem here. Previously, i have 2 listeners that listens to 2 listboxes for its variable, to display other stuff. It works nicely, but when i add in a third listbox,the whole flash jumbled up and it cannot receive the variable from its intended recipient previously, and always stick to 0


Code:
//////////////////////////////////////setup items in top most layer listbox
function setupTopList() {
f_Top.reverse();
for(var item in f_Top){
topList.addItem(f_Top[item]);
}
topList.sortItemsBy("label", "ASC")
}

//////////////////////////////////////////////// input items in 2nd layer listbox

function setupSecList(q) {
fSecList.removeAll();
all = counting.length
SecList._visible = false;
for(p=0; p<all; p++) {
if(f_TopR[q] === fTop[p]) {
featureList._visible = true;
featureList.addItem(fTitle[p]);
trace("p in setupSecList= " + p) // still ok here
}
}}

/////////////////////////////////////////////////////////////input items in thirdList
function setupThirdList(p) {
trace("p in thirdlist = " + p) // p is not working anymore!
thirdList._visible = false;
thirdList.removeAll();
for (j=0; j<total; j++) {
if (fTitle[p+1]=== thirdTitle[j]) {
thirdList._visible = true;
thirdList.addItem(thirdWorks[j]);
}
}}}


///////////////////////////////////////////////////////////////////////top listener
myTopBoxListener = new Object();
myTopBoxListener.change = function ( eventObj ){
var eventSource = eventObj.target;
var selectedObj = eventSource.selectedItem;
var q = eventSource.selectedIndex;
var selectedObjLabel = selectedObj.label;
setupSecList(q);
}

topList.addEventListener ("change", myTopBoxListener);

////////////////////////////////listens to secList for command
myListBoxListener = new Object();
myListBoxListener.change = function ( eventObj ){

var eventSource = eventObj.target;
var selectedObj = eventSource.selectedItem;
var p = eventSource.selectedIndex;
var selectedObjLabel = selectedObj.label;
clickChange(p);
setupThirdList(p);
trace("p in listbox listener= " + p)
}

secList.addEventListener ("change", myListBoxListener);

function clickChange(p){
trace("p in clickchange = "+ p)
if (loaded == filesize) {
picture.loadMovie(image[p-1]);
desc_txt.text = description[p-1];
}
}

//featureList.setChangeHandler(samplist(p+1)); should i put this line in??

i hope my question is understood. appreciate any help ..

Listeners? I Can't Figure Out Listeners/broadcasters
Hello AS gurus... I need your help.
I have a movieclip - which when it stops it assigns a value to a global variable. (ie. _global.variable = 3)
Now, how do I have a listener on my main timeline that is listening for changes in the global variable & will do a certain number of commands based on the value of this variable.

ie.  If _global.variable ever equals 3, I want it to do something & if _global.variable ever equals 4, I want it to do something else.  please help



Using NetStream.time On Rtmp Live Stream (broadcaster=receiver)
I am trying to synchronize a live stream (which is broadcasted from the flash player plugin) with some scripted actions. The problem is, that the displayed frames of the rtmp stream do not correlate to the netStream.time property on the receiver side. In fact, i do not understand at all, how the property is rendered on the receiver, since i can not recognize any dependencies to e.g. bufferLength.
Does anybody now, how it is calculated? I tried with Red5 and Wowza and they seem to behave similar. I guess, FMS would not make any difference (if so: lease let me know!), since i assume that the property is rendered during the encoding process i.e. by the plugin.

Linking Visual Basic Button To Actionscript Broadcaster Object
hi all,

does any one know how to link a visual basic button to actionscript broadcaster object? If yes, please help me out.

korkor5

Linking Visual Basic Button To Actionscript Broadcaster Object
hi all,

does any one know how to link a visual basic button to actionscript broadcaster object? If yes, please help me out.

korkor5

Listeners ?
I've created a generic object, 'txListener', and I want it to listen for any textfield that receives focus. I'm still learning the capabilities of flash broadcast methodology and have got as far as the code below. It traces the key pressed in the textBoxTx field.

txListen = new Object();
txListen.onChanged = function() { //Would like this to be "onReceiveFocus" somehow.
trace("key pressed code: "+Key.getCode());
}; // I belive this additional semicolon is the correct syntax.
textBoxTx.addListener(txListen);//Would like all textfields registered dynamically.

1. How can I listen for when the textBoxTx field receives focus.

2. Is it possible and how can I listen for any textfield that receives focus - is there a way to dynamically register, 'addListener', to the txListen object?

Thanks to anyone that understands this

MX Help On Key Listeners
Does anyone have a tutorial or an example on how to use the Key Listener for Flash MX? I can use Key.isDown just fine, but I have no idea how the Key Listener works. Anyone have a link or a tutorial or anything?

I'm trying to make something move diagonally when I press a combination of two keys, either the up and the right arrow, or the down and left, etc. I can't do it using Key.isDown, so I'm assuming that it requires the key listener. Any help out there?

Riki

Key Listeners
How do you add a listener to a specific key on the keyboard, and not just to the generic Key object like this:
code:
myListener = new Object();
myListener.onKeyDown = function () {
trace ("You pressed a key.");
}
myListener.onKeyUp = function () {
trace ("You released a key.");
}
Key.addListener(myListener);

What Can Listeners Do?
i recently started using listeners for checking key strokes and i was wondering, can listeners be used for anything else? can i somehow use them for hitTests? is there ANY way of doing a constant hit test w/o onEnterFrame ?

Those D*mn Listeners Again...
Hello,

In my movie there are several objects (draggable windows and such) which need to respond to a listener command. All my instances are on different target levels.

How do I add a listener "inside" a symbol so code is executed when a listening command is received? A window symbol in this case.

The plan is that the symbol will update its color as soon as a message is broadcasted. The color value is in a variable.

--------------------------------------
this needs to be executed when a listening command is received:

temp_color2 = _root.GUIcolormain.split("#")[1];
myColor2 = new Color(datarget);
myColor2.setRGB("0x"+temp_color2);

--------------------------------------

So I need something like :

if a listener command is received do something.

Thankz....

Listeners
I don't understand what listeners really do...i was wondering if somebody could show or tell me...

thanks

P.S. I know this sounds stupid probably but i just don't know.

Listeners Uh?
Hi,
can someone tell me what the point of listeners are in MX2004? why are they needed, whats special about them??

Key Listeners?
Hi All,

Is there a simple way to capture keystrokes? I've been making separate buttons for each key with, for example, an on(press"1")
to get the number one to appear in a textbox. Is there an easier way to do this?

Thanks!

[F8] Listeners /
Hi there,

basically - I want to fade out a MC when a certain variable is 1.

I think I need to use a listener, but not sure (have searched forum, and livedocs)

What is the best way of doing this?


e.g: when allLoaded = 1 then fadeOutMC(faded_mc);

Key Listeners
Anyone know if it's possible to access all listeners currently assigned to the Key class?

[F8] Listeners Help
I want to lock the key board out so they can no longer press keys to interface with my flash object once they have pressed a key. How is this possible?

Im using the code below to Check what key they have pressed. once they press one of those keys i dont want them to be able to "BUZZ in" using the keys no more.

Game consists of 3 players each have a key to press to buzz in and have control of the interface to answer the question.

Can this be done?



Code:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
// compare return value of getCode() to constant
if (Key.getCode() == 65) {
trace("Virtual key code: "+Key.getCode()+" (ENTER key)");
} else if (Key.getCode() == 66) {
trace("Virtual key code: "+Key.getCode()+" (ENTER key)");
} else if (Key.getCode() == 76) {
trace("Virtual key code: "+Key.getCode()+" (ENTER key)");
}
};
Key.addListener(keyListener);

Xml Listeners
I was wondering if there is anyway to grab the information from an XML file without using a listener? I have searched google and have only been able to find it using listeners. All I want to do is load an XML, parse the info, an process it to do what I need to do.

How Many Listeners?
I have a button that when clicked, loads

1. an external swf (via MovieClipLoader Class)
2. some variables from an external txt (via LoadVars class)
3. an external picture (via MovieClipLoader Class)

How can I be notified that all of them have been loaded? Should I use 3 listeners? Can this be done by simple 1 listener?

Listeners And Such
Hello, I am new here!

I have a question regarding listeners.

Here is my code:

var myInterval:Number;
musicPlayer._alpha = 0;

Mouse.addListener(myListener);

myListener.onMouseMove = function() {
if (aHitArea.hitTest(_root._xmouse, _root._ymouse, true)) {
myInterval = setInterval(mChange, 5);
}
};

function mChange() {
musicPlayer._alpha++;
updateAfterEvent();
if (musicPlayer._alpha == 100)
clearInterval(myInterval);
}


now, how would you suggest me fading the alpha on musicPlayer when the mouse is off the aHitTest area?

I added an else statement:

myListener.onMouseMove = function() {
if (aHitArea.hitTest(_root._xmouse, _root._ymouse, true)) {
myInterval = setInterval(mChange, 5);
} else if (bHitArea.hitTest(_root._xmouse, _root._ymouse, true)) {
musicPlayer._alpha = 0;
}
};

but that only changes the alpha to 0 for a second then sets it back to 100.

i know this is a long one, but any help is always appreciated.

also, on listners and mousemove - does this affect the cpu cycles? at some point should i removeListener?

thanks again

Help With Listeners...
I am creating a class (Blog) that loads data from a database and then handles that data. The first method - blog.getData(); - in the class uses LoadVars to get the data from the db. The second method - blog.makeTitles(); - I have uses the number of records returned from the database for determining the loop length through which to process data.

So if I get 5 records returned I want to process the title of each of the 5 records.

var newBlog:Blog = new Blog();

// So I make the first call:
newBlog.getData();
// Then the second call:
newBlog.makeTitles();

The problem is that I need to wait until the data is returned from the db before making the second call. I believe the solution is to use a listener on the first call but I am unsure on how to set one up.

Listeners In AS3
Hi Masters

I move a character by mouse only in x axis. In order to move I use Event.ENTER_FRAME listener.
When the character moves to right I want to play a movieclip inside the characer movieclip, and the same for left side to simulate a walk. In order to do it, I used:

private function onEnterFRAME(e:Event):void{
...
if(mouseX > character.x){
character.gotoAndPlay(2); //I've got a mc to right_walk inside character mc
}else{
character.gotoAndPlay(13); //the same for left_walk
}
}

But it just play the frame 2 and doesn't play all the mc, and the same for frame 13 (left walk).
I'm trying the same code inside of MouseMove.MOVE listener and while you are moving the mouse it doesn't work and just play the mc when the mouse is stop.

What kind of listener or another way should I use?

Thank you for your time reading this

Help With Listeners?
Hey I have just discovered listeners and I want to know exactly what they are and what you can do with them. I understand that they monitor when an event has happened, but then what? Can someone help me out and show me some example code maybe, or give me an alternate way to make something happens when the mouse stops moving??? thanks

Listeners In AS3
I have a quick question about adding a listeners to the objects/movie clips in actionscript 3.0.
Is it possible to use an event listener other than mouseEvent?

i.e. if I'd like to trigger myFunction() only when someMovieClip.width property changed, is it possible to set listener which listens for property of object/movie clip - like height, width, x, y, alpha, etc.

Xml And Listeners
so here's the skinny,

i am trying to a create a mobile store-front for a product line. there are three products. each product has n-number of items that will be displayed in an empty movie clip. also, each product gets a different frame that a button on the stage points to. product images are loaded into the flash player via xml. a customer scolls through the product images with lieft and right [next or previous] buttons. i've got that much figured out. /// however, here comes the tricky part. i want customers to be able to take a closer look at the products. basically, i want them to be able to rollover the product [or click on a button] and get a pop-up that will show a zoomed in image of product designs. I would like to manage these close-up images with xml as well. i was thinking that maybe i could load two images into the flash player, where one would be loaded into an invisible empty movie clip that becomes visible when activated... either by a rollover or a button...(?) i was also thinking that i could create a listener that would map the product image loaded to a corresponding design image in an xml file... which would be loaded into a pop upon activation [the button would make the pop up visible and load into an image from an xml file)...(?) but, i'm not sure which is the most viable strategy. also, i want to map a button to each design that will take the customers to a check out with that product allready in the bin, and manage these variable links with xml as well.

i'm not as well aquanted with xml as i would like to be, and yes i could do this without xml, but since i want these storefronts to be mobile xml seems like the most efficent way to manage the storefronts and give each the storefront a unique line. if i can get this much figured out, i think i'll be fine figuring out how to let users create their own xml files.

thanks.





























Edited: 09/06/2007 at 11:19:34 PM by Extra Taylor

Different Listeners
I'm having a field day with questions today!

I've got several classes and one of them happens to be a generic (read: reusable/ui independent) music player class. I wanted to have a different class (the ui) display the currently playing song name in a text field. It's not an issue with individual tracks but when playing playlists I need to be able to tell when the song has changed from within the ui class (Sound.onSoundComplete can't be used).

I'm guessing that listeners hold the answer but I've come across 3 different kinds of listeners (unless I'm confused); AsBroadcaster, EventDispatcher and Object.watch. Here's were I got lost, I can't seem to find a lot of info on any of them apart from AsBroadcaster!

Any help?

Listeners
Does anyone know how much memory/resources listeners take? That is if I create a bunch of listeners within my movie do I need to remove them after they aren't needed anymore? Thanksssss for the help.

Help With Listeners
Could anyone explain me how "addEventListener" and other stuff that is connected with listeners works, because i have no practic with that and i dont know a bit of it. Thanks, links to tutorials with that stuff should also be great!

Key Listeners
hey,

I'm looking for an alternative to
Code:
on(keypress){} ..
I went tot this site.. http://flash-creations.com/notes/asclass_key.php
But this code will come into effect if the key is pressed.. and also when it's down..

How do i make it so that it only registers the key when it is pressed.. but not when it is held down?

( so it's like a one time thing only .. also.. this is for keyboard events.. not the mouse events)

Thanks

Help With Listeners.
For the life of me... I can't get listeners to work, what is going wrong here? I get this error...

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at player$iinit()
at game$iinit()




Code:
package {
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.KeyboardEvent;

public class player extends Sprite {
private var speed = Math.random() *2+2;
private var timer:Timer = new Timer(30);

public function player() {
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);

}

private function reportKeyDown(event:KeyboardEvent):void {
trace("Key Pressed: " + String.fromCharCode(event.charCode) +
" (character code: " + event.charCode + ")");
}

private function onTimer(event:TimerEvent):void {


}
}
}

Help With Listeners
I'm in trouble, again. Thanks for your time.

I need an externally loaded mc (a listener) to execute a tween when another movie clip (a broadcaster) is pressed. So, when you press on mc1, mc2 executes a function. Sounds so simple. And I feel I almost cracked it. Now, I know the theory behind broadcasters and listeners, but my code simply doesn't work. I must be dumb since I couldn't figure it out from the senocular's tut on broadcasters and listeners.

To try to illustrate the problem more: listeners are a couple of arrows, left and right. They are movie clip buttons that work on the rewind principle. There's an externally loaded mc at the stage that executes its intro tween (nothing special), and when it stops I want it to start listening to the arrows. So, when on(release) on the arrow occurs, externally loaded mc executes it's outro tween, and at the end calls for the next externally loaded mc on the stage.

Now, to add another question; I have 6 externally loaded clips, called by the arrows. When the first and the last one are on the stage, I'd like to disable the previous, and the next buttons, respectively. I thought I'll just do arrow.enable = false in the first and the last clip. Any better way of doing it?

Again, thanks for your time.

Listeners Listeners And Listeners
Hello,

I have a question about listeners. Theres a motion text on my fla and i want to trigger a sound event when the motion starts and after that motion finishes the sound ends.
Could anyone give me an example or a document link about listeners. (AS2)

Listeners?
How would I remove listeners? I know I have to use removeListeners, but how? I am trying to load different movies at differnet frames in a main movie and I need to remove the object from the listener once it's loaded so I can use the same key again.

Thanks,
John

Key Listeners
Hi All,

Is there a simple way to capture keystrokes? I've been making separate buttons for each key with, for example, an on(press"1")
to get the number one to appear in a textbox. Is there an easier way to do this?

Thanks!

Why Do I Get The Last Value On My Listeners?
Hi all!

For some reason the following code doesn't work! It generates n number of menu elements but no matter what element I click on the event functions traces the data for the last element created by the loop. why is that? please help!!

Code:

private function generateMenu():void {
         for(i = 0; i < productMCs.length; i++) {
            var mc:Class = getDefinitionByName("btn_prod"+i) as Class;
            var currentBtn:Object = new mc();
                        
            currentBtn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverMenu);
            currentBtn.addEventListener(MouseEvent.MOUSE_OUT, mouseOutMenu);
            currentBtn.addEventListener(MouseEvent.MOUSE_DOWN, mousePressMenu);
            
            currentBtn.x = 50+(i * 100);
            currentBtn.y = totalHeight - (this.height + 10)
            menuCon.addChild(DisplayObject(currentBtn));
            trace("Added "+currentBtn+" to the Menu");
         }
      }

Listeners
I'm struggling to understand listeners and events

I'm looking to change the postion of a movieclip on the stage when the mouse pointer gets below a certain "y"position.

can anyone offer any information.

Key.? Listeners Flash MX
Hi all,

I've come across a problem during the creation of a flash movie..

Basically the movie consists of two scenes. Key.LEFT moves from "help" scene to "interface" scene and numpad 9 goes to "help" from "interface".

It works fine from "help" to "interface" the Key.removelistener(helpListener) disables the Key.LEFT. But on going back to the "help" scene the Key.removeListener(interListener) doesn't disable numpad 9 enabling the user to jump to and from each scene with each press (code at bottom).

Is this usual behaviour? Does it have anything to do with help being the first scene and trying to remove something that hasn't been created yet?

Any work arounds or solutions to this problem would be greatly appreciated!!

Thanks in advance,

Ben Gazzard

Each scene;
----------------------------------------------------------------------
Help:

Key.removeListener(interListener);
helpListener = new Object();
helpListener.onKeyDown = function() {
if (key.LEFT) {
gotoAndPlay("Scene 1", 1);
}
};
Key.addListener(helpListener);
stop();

----------------------------------------------------------------------
Interface:

Key.removeListener(helpListener);
interListener = new Object();
interListener.onKeyDown = function() {
if (key.isdown(105)) {
gotoAndPlay("help", 1);
}
};
Key.addListener(interListener);
stop();

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