PDA

View Full Version : onChange event problem with components


Daevid
08-28-2005, 12:34 PM
I've been trying to declare an onChange-function to a combobox component like this (from an extended movie clip that contains the combobox "Type"):

Type.onChange = function (){
trace ("changed!")
}

This works with with onRelease-event for buttons etc, but for some reason flash ignores this function. If I instead attach a similar function directly to the combobox:

on(change) {
this.onChange ()
}

... it sends the event correctly. I can't understand why, and would rather not have any code internally in the fla-file.

Can anybody explain why this is?

/David

Xeef
08-28-2005, 12:57 PM
hi and welcome to As.Org

the combobox has NO "onChange"
BUT
ComboBox.change
Availability
Flash Player 6 (6.0 79.0).

Daevid
08-28-2005, 04:00 PM
Thanks for both the help and the welcoming! Unfortunatley I can't get it working with the "change" event either:

Type.change = function (){
trace ("changed!")
}

I've tried the more conventional listener syntax aswell, but i guess i'll have to stick to my "ugly" solution.

/David

Xeef
08-28-2005, 05:12 PM
listenerObject = new Object();
listenerObject.change = function(eventObject) {
trace("changed!");
};
Type.addEventListener("change", listenerObject);

Daevid
08-29-2005, 08:48 AM
Thanks,

this works if I put the script attached to a movie clip in flash (in a onClipEvent(load)-event), BUT it still doesn't work when I try to attach it through an external .as class (within the MC:s creator function). Is it possible that the change event isn't supported in AS2?

Sorry for being so picky but I try to avoid having scripts inside the fla-file...

I really appreciate you help, though.

/David

Xeef
08-29-2005, 10:31 AM
upload the files so i can test

Daevid
08-29-2005, 12:00 PM
Here is a fla and an as file where the problem is isolated. Thanks.

/David

Xeef
08-29-2005, 01:08 PM
class testMovieClip extends MovieClip {
var type;
var listenerObject = new Object();
function testMovieClip() {
mx.events.EventDispatcher.initialize(type);
listenerObject.change = function(eventObject) {
trace("changed!");
};
type.addEventListener("change", listenerObject);
}
}

Daevid
08-29-2005, 02:26 PM
Sorry, still no success. Have you tried the files on your system?

Any clues on why you need to initialize the change-event for comboboxes, when button event work OK without?

Thanks anyhow!

/David

Xeef
08-29-2005, 05:42 PM
no i dint test you files because you was uploading an SWF
there you see so or so no traces

i have a slight idea why you need to initialize but

if you realy wana know you need to ask senocular

Daevid
08-30-2005, 08:04 AM
Sorry for uploading the SWF... not the first time I've made that mistake! I'm still new to flash so I'm really grateful for you helping me out.

I think I've found what was my problem: I had given the MC an instance name, for some reason this stops the change-event. If I remove the instance name everything works OK!

I can't figure out why this is though.

Thanks for your help! Hope to learn fast so I can contribute constructively to this forum myself!

/David