all groups > flash actionscript > january 2006 >
You're in the

flash actionscript

group:

Event Dispatcher problem


Event Dispatcher problem foutuguy
1/31/2006 8:50:13 PM
flash actionscript:
I am discovering the event dispatcher concept in flash and am trying to get it
working.
I have a site that is made of a main swf that will load multiple swf. The site
has 2 languages.
The ultimate goal, in my project, is when the user selects another language,
to dispatch a message,
heard by all the different swf files, that will then separately update their
own elements to the proper
language.

To start simple, I have the following:
- one main file, called test.fla. It has only one frame and nothing in it,
except this code :
stop();
_root.createEmptyMovieClip("dyntitle", this.getNextHighestDepth());
dyntitle._x = 0.0;
dyntitle._y = 0.0;
dyntitle.loadMovie("title.swf");

title.fla has also one frame only containing a button called "flag"
this frame has the following code;
stop();
flag.onRelease = function(){
var test:LangUpdater = new LangUpdater();
test.updateLang();
}

I also have a separate class file LangUpdater.as:
import mx.events.EventDispatcher

class LangUpdater{
function dispatchEvent() {};
function addEventListener() {};
function removeEventListener() {};

function LangUpdater(){
mx.events.EventDispatcher.initialize(this);

}

function updateLang(){
var eventObject: Object = {target:_root, type:'languageToUpdate'};
dispatchEvent(eventObject);
}
}

It does not work, meaning, i do not get the trace out. However, if I move the
2 lines
var test:LangUpdater = new LangUpdater();
test.updateLang();

in the test.fla file, then it works. What did i do wrong? Obviously, there is
something i did not caught.

Thanks in advance for your help that will be appreciated.
Re: Event Dispatcher problem LuigiL
2/1/2006 3:40:25 PM
In test.fla:
stop();
_root.createEmptyMovieClip("dyntitle", this.getNextHighestDepth());
dyntitle._x = 0.0;
dyntitle._y = 0.0;
dyntitle.loadMovie("title.swf");

var lang_test:LangUpdater = new LangUpdater();
var lang_listener:Object = new Object;
lang_listener.languageToUpdate = function(evtObj) {
trace("The language is updated");
}
lang_test.addEventListener("languageToUpdate",lang_listener);

In title.fla:
stop();
flag.onRelease = function(){
//var test:LangUpdater = new LangUpdater();
_root.lang_test.updateLang(); // call instance in parent
}
Re: Event Dispatcher problem foutuguy
2/1/2006 11:12:25 PM
ok, i see know how that works and why I was wrong.
Thank you so much for your time!
AddThis Social Bookmark Button