• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Enrique Chavez

Professional WordPress Development

  • Home
  • Blog
  • Contact Me
  • Hire Me

Simple onReleaseOutSide en AS3

AS3 · Oct 8, 2007

Una de las tantas cosas que se extrañan de ActionScript 2 son algunos eventos del mouse que son, sin duda, bastante útiles a la hora de trabajar en nuestros proyectos.

El evento que más se extraña es onReleaseOutside, este evento lo uso tanto como los demás así­ que habí­a que hacer algo al respecto.

Escribí­ una pequeña clase que detecta dicho evento y lanza el dispatch.

Aquí­ está la clase.

[as]
package com.tmeister.utils
{
import flash.display.InteractiveObject;
import flash.events.MouseEvent;
import flash.events.Event;

public class MouseEvents
{
static public const RELEASE_OUTSIDE = “onReleaseOutside”
private var target:InteractiveObject;
function MouseEvents(obj:InteractiveObject)
{
target = obj;
createChildrens();
}
private function createChildrens():void
{
target.addEventListener(MouseEvent.MOUSE_DOWN, onPress);
}
private function onPress(event:MouseEvent):void
{
target.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
}
private function onRollOut(event:MouseEvent):void
{
if(event.buttonDown)
{
target.stage.addEventListener(MouseEvent.MOUSE_UP, onReleaseOutSide);
}
target.removeEventListener(MouseEvent.ROLL_OUT, onRollOut);
}
private function onReleaseOutSide(event:MouseEvent):void
{
if( event.target == target )return
var nEvent:Event = new Event(RELEASE_OUTSIDE);
target.dispatchEvent(nEvent);
target.stage.removeEventListener(MouseEvent.MOUSE_UP, onReleaseOutSide);

}
}
}
[/as]

El modo de uso.

[as]
import com.tmeister.utils.MouseEvents;
var boxes:Array = [box0, box1, box2, box3];

for each (var box in boxes)
{
var oros:MouseEvents = new MouseEvents(box);
box.addEventListener(MouseEvents.RELEASE_OUTSIDE, releaseOut);
box.addEventListener(MouseEvent.CLICK, click);
}
function releaseOut(evt:Event)
{
out_txt.appendText(“nRELEASE OUTSIDE “+evt.target.name);
}
function click(evt:MouseEvent)
{
out_txt.text = “Click Normal “+evt.target.name;
}
[/as]

Y este el ejemplo final.

[FLASH]http://tmeister.dev/as3/oros.swf,300,250[/FLASH]

Saludos!! 8)

Related

Filed Under: AS3 Tagged With: AS3

Enrique Chavez

Senior Full Stack WordPress developer & WordPress Enthusiast -
Spend my days building cool stuff with WordPress.

Reader Interactions

Comments

  1. zguillez says

    Oct 8, 2007 at 6:23 pm

    Bueno código 😉
    Hace un tiempo vi una clase de André Michelle para hacer lo mismo, y además añadá eventos onDragOut, onDragOver: http://www.codigo.as/blog/?p=78

    Reply
  2. Rafeo says

    Oct 15, 2007 at 7:38 pm

    Hace un poco también me andaba quebrando el coco tratando de implementar el mentado onReleaseOutside. Muy muy útil :D.

    Reply
  3. Rafeo says

    Oct 15, 2007 at 7:43 pm

    Oye, por cierto… mi blog hace rato nomás no 🙁 .

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

SUBSCRIBE FOR UPDATES

Like what you’ve read? If you're interested in my email, sign up here. No spam I promise!

My WordPress Plugins

  • JWT for WP REST API
  • WP Simple Mail Sender
  • Idea Factory

My SideProjects

  • WordPress Plugin Boilerplate Generator

My Profiles

  • WordPress
  • GitHub
  • Linkedin

Additional Info

  • Blog
  • Hire Me
  • Contact Me

© 2021 Enrique Chavez