[x]
Forum
Forum
[x]  
~Nikush7:iconNikush7: May 10, 2008, 11:50:57 AM
hey again :D

i want a movieclip in flash to listen out for a custom event that ive created, and for some reason when i add an event listener to it, it doesnt listen out for the custom event.

ive played aorund with it and managed to get another movieclip to listener for it, but its not realy what i want.

all i want to know is why the movieclip wont listen for the event, are there certain rules for applying event listeners to movieclips or something?

Devious Comments

love 0 0 joy 0 0 wow 0 0 mad 0 0 sad 0 0 fear 0 0 neutral 0 0

=L-iNC:iconL-iNC: May 10, 2008, 3:34:10 PM
Are you sure the event is actually dispatched?

--
DeviantArt is NOT all about the number of pageviews.
Prints available.
--
New Browse Feature: browse by advanced critique we
~Nikush7:iconNikush7: May 10, 2008, 11:45:38 PM
yh its definitely dispatched for two reasons, firstly i put a trace statment inside the event, so when its dispatched that would execute, secondly i stated that another movieclip on the stage was able to listen out for the event, and perform a function after that.
`summaro:iconsummaro: May 11, 2008, 4:49:11 AM
Code please.

--
The DataGrid control is intended for viewing data, and not as a layout tool like an HTML table - Adobe
~Nikush7:iconNikush7: May 11, 2008, 8:20:50 AM
ok let me explain the prject i am creating, i want to create a colour chooser like the RGB sliders you can find in Flash, Photoshop etc... So i have set up 3 sliders on the stage, when you slide them, they dispatch the percentage that they have moved:

(this is one of the functions used to move the slider, it can be found in the base class assigned to the movieclip)
private function thumbMove(e:MouseEvent):void
{
thumb.x = mouseX - xOffset;
if(thumb.x > xMax)
thumb.x = xMax;
if(thumb.x < xMin)
thumb.x = xMin;
dispatchEvent(new SlideEvent(thumb.x / xMax, Col));
e.updateAfterEvent();
}

I know this works because i set up a trace statement inside the custom event, and the trace worked, so i am sure the event is being dispatched.


I also have a document class assigned to my .fla, in the class i added this line of code:

(i have a movieclip on the stage called "box", this is what i want to add the lsitener to, but it doesnt quite work).
box.addEventListener(SlideEvent.SLIDE, changeCol);

i have tried adding the listener to the slider movieclip, and when i tried that, the listener worked, and the function was executed, but it wont work for the box movieclip.

sorry if i havent given you enough, my code spreads across 4 actionscript files, so i just picked where i thought the problem came from.
=L-iNC:iconL-iNC: May 11, 2008, 9:57:59 AM
Shouldn't that be:

dispatchEvent(new Event(SlideEvent.SLIDE, true));


--
DeviantArt is NOT all about the number of pageviews.
Prints available.
--
New Browse Feature: browse by advanced critique we
~Nikush7:iconNikush7: May 11, 2008, 1:50:13 PM
sorry to say that doesnt work.
Event still, my dispatchevent works fine, its the eventlistener im having trouble with.
thanks for the trying though.
`summaro:iconsummaro: May 11, 2008, 6:13:33 PM
Not if he's made his own specific sub class of the Event class.

--
The DataGrid control is intended for viewing data, and not as a layout tool like an HTML table - Adobe
`summaro:iconsummaro: May 11, 2008, 6:18:06 PM
Ok, you're adding the event listener to the object box - that means that box is dispatching the event. If box is not dispatching the event, or it's not being dispatched from an object in box's display stack, it's not going to pick it up.

Instead, say your slider's name is slider, and slider is the object that dispatches events.

If you want box to respond to a SlideEvent that slider dispatches, then you'll need to write:

slider.addEventListener(SlideEvent.SLIDE, box.handleSlideEvent);


This, of course, needs to be in a scope level that it can see both slider and box, and it could get messy pretty fast.

If you're dealing with a lot of custom events, my suggestion is to use an Observer design pattern instead of relying on Flash's event system.

--
The DataGrid control is intended for viewing data, and not as a layout tool like an HTML table - Adobe
~Nikush7:iconNikush7: May 12, 2008, 2:08:19 PM
that works just fine. but its still not what i was after, i was asking why icouldnt add the listener to the box movieclip.

i want the slider to dispatch the event, and the box to listen for it.

thanks still :)