Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthored
    • CommentTimeOct 20th 2009 edited
     
    Pardon me if this has already been addressed. I've searched and read through many threads and haven't found a solution to this problem:

    Is there a way to stop or add LinearDrag to a particle when a user rolls over it? Anything I add to the emitter affects all the particles at once. If possible, how do I access each particle within the emitter?
    • CommentAuthorRichard
    • CommentTimeNov 2nd 2009 edited
     
    Hi Ed

    Note first that the renderers have their mouseChildren property set to false by default. To enable mouse events on the particles, you'll need to set the mouseChildren property of the renderer to true.

    You access the particles through initializers or actions. If you added an initializer that set the MouseOver and MouseOut event handlers for all particles, that would give you the access you need. Something like this

    package
    {
    public class ParticleRollover extends InitializerBase
    {
    private var _overHandler:Function;
    private var _outHandler:Function;

    public function ParticleRollover( overHandler:Function, outHandler:Function )
    {
    _overHandler = overHandler;
    _outHandler = outHandler;
    }

    override public function addedToEmitter( emitter:Emitter ):void
    {
    emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, removeListeners, false, 0, true );
    }

    override public function removedFromEmitter( emitter:Emitter ):void
    {
    emitter.removeEventListener( ParticleEvent.PARTICLE_DEAD, removeListeners );
    }

    private function removeListeners( event:ParticleEvent ):void
    {
    IEventDispatcher( event.particle.image ).removeEventListener( MouseEvent.MOUSE_OVER, _overHandler );
    IEventDispatcher( event.particle.image ).removeEventListener( MouseEvent.MOUSE_OVER, _outHandler );
    }

    override public function initialize( emitter:Emitter, particle:Particle ):void
    {
    IEventDispatcher( particle.image ).addEventListener( MouseEvent.MOUSE_OVER, _overHandler, false, 0, true );
    IEventDispatcher( particle.image ).addEventListener( MouseEvent.MOUSE_OUT, _outHandler, false, 0, true );
    }
    }
    }
    • CommentAuthormazwat
    • CommentTimeMay 10th 2011
     
    Hi Richard,

    I think Flint is a fabulous system and I am really just beginning to unlock it's potential. However I am struggling with some of the coding side of things.
    I too am looking to implement the movement of individual particles, and I came across this post.
    I have added this package that you have written above to my initializer base, But I am not sure about how to implement this as code in the main flash file.
    Could you possibly give me some pointers. thanks
    • CommentAuthorRichard
    • CommentTimeMay 12th 2011
     
    The class mentioned above has since been added to Flint's core initializers. The documentation is here. To use it, do something like this

    ...
    var mouseHandlers:MouseEventHandlers = new MouseEventHandlers();
    emitter.addInitializer( mouseHandlers );

    renderer.mouseEnabled = true;
    renderer.mouseChildren = true;

    mouseHandlers.overHandler = onMouseOver;
    mouseHandlers.outHandler = onMouseOut;

    function onMouseOver( event:MouseEvent ) : void
    {
    ...
    }

    function onMouseOut( event:MouseEvent ) : void
    {
    ...
    }


    Also, you must use a DisplayObjectRenderer because that is the only renderer where particles are discrete objects with their own events.