Flash Mouse.hide() cmd+tab(alt+tab) bring the mouse back

Posted by DickieBoy on Stack Overflow See other posts from Stack Overflow or by DickieBoy
Published on 2012-10-22T16:58:39Z Indexed on 2012/10/22 17:00 UTC
Read the original article Hit count: 208

Filed under:
|

Having a bit of trouble with

Mouse.show()

and losing focus of the swf

This isn't my demo: but its showing the same bug http://www.foundation-flash.com/tutorials/as3customcursors/

What i do to recreate it is:

mouse over the swf, hit cmd+tab to highlight another window, result is that the mouse is not brought back and is still invisible, (to get it back go to the window bar at the top of the screen and click something).

I have an area in which movement is detected and an image Things I have tried

package  {

import flash.display.Sprite;
import flash.display.MovieClip;
import com.greensock.*;
import flash.events.*;  
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.utils.*;
import flash.ui.Mouse;


public class mousey_movey extends MovieClip {

    public var middle_of_the_flash;


    //pixels per second
    public var speeds = [0,1,3,5,10];

    public var speed;
    public var percentage_the_mouse_is_across_the_screen;
    public var mouse_over_scrollable_area:Boolean;

    public var image_move_interval;

    public function mousey_movey() {
        middle_of_the_flash = stage.stageWidth/2;
        hot_area_for_movement.addEventListener(MouseEvent.MOUSE_OVER, mouseEnter);
        hot_area_for_movement.addEventListener(MouseEvent.MOUSE_OUT, mouseLeave);
        hot_area_for_movement.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
        stage.addEventListener(Event.MOUSE_LEAVE, show_mouse);
        stage.addEventListener(MouseEvent.MOUSE_OUT, show_mouse);
        stage.addEventListener(Event.DEACTIVATE,show_mouse);
        hot_area_for_movement.alpha=0;
        hot_area_for_movement.x=0;
        hot_area_for_movement.y=34;
    }

    public function show_mouse(e) {
        trace(e.type)
        trace('show_mouse')
        Mouse.show();
    }

    public function onActivate(e) {
        trace('activate');
        Mouse.show();
    }

    public function onDeactivate(e) {
        trace('deactivate');

    }


    public function get_speed(percantage_from_middle):int {
        if(percantage_from_middle > 80)
        {
            return speeds[4]
        }
        else
        {
            if(percantage_from_middle > 60)
            {
                return speeds[3]
            }
            else
            {
                if(percantage_from_middle > 40)
                {
                    return speeds[2]
                }
                else
                {
                    if(percantage_from_middle > 20)
                    {
                        return speeds[1]
                    }
                    else
                    {
                        return 0;
                    }
                }
            }
        }
    }

    public function mouseLeave(e:Event):void{
        Mouse.show();
        clearInterval(image_move_interval);
    }

    public function mouseEnter(e:Event):void{
        Mouse.hide();
        image_move_interval = setInterval(moveImage,1);
    }

    public function mouseMove(e:Event):void {
        percentage_the_mouse_is_across_the_screen = Math.round(((middle_of_the_flash-stage.mouseX)/middle_of_the_flash)*100);
        speed = get_speed(Math.abs(percentage_the_mouse_is_across_the_screen));
        airplane_icon.x = stage.mouseX;
        airplane_icon.y = stage.mouseY;
    }

    public function stageMouseMove(e:Event):void{
        Mouse.show();
    }

    public function moveImage():void {

        if(percentage_the_mouse_is_across_the_screen > 0)
        {
            moving_image.x+=speed;
            airplane_icon.scaleX = -1; 
        }
        else
        {
            moving_image.x-=speed;
            airplane_icon.scaleX = 1; 
        }
    }

}

}

Nothing too fancy, im just scrolling an image left of right at a speed which is generated by how far you are from the middle of the stage, and making an airplane moveclip follow the mouse.

The events:

stage.addEventListener(Event.MOUSE_LEAVE, show_mouse);
stage.addEventListener(MouseEvent.MOUSE_OUT, show_mouse);
stage.addEventListener(Event.DEACTIVATE,show_mouse);

All fire and work correctly when in the browser, seem a little buggy when running a test through flash, was expecting this as ive experienced it before.

The deactivate call even runs when testing and cmd+tabbing but shows no mouse.

Any help on the matter is appreciated

Thanks,

Dickie

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash