views:

283

answers:

2

I built this incredibly brilliant scrolling thumbnail image viewer for a client in flash actionscript 3. (Basically it just scrolls up or down depending on the mouse position). It works so so, (I can never get the percentages right so that it shows the top most image) but, that's beside the point. What is REALLY irking me is when I have the browser window open with my .swf loaded and I click on another app on my desktop, the stupid scrolling thumbnail area in the browser window starts to freak out.

"Where is my mouseY??!?!?!?" I assume it is thinking.

Is there a stage.Unfocus event I can tell my scrolling thumbnail area to STFU with?

I'd even consider writing some javascript to call a flash function, if that's a preferred technique. Thanks in advance.

function checkMousePos(e:Event):void
{ 
  if(mouseX < 145){
    try{
        var sHeight:int = MovieClip(root).stageHeight;
    }catch(Error){
        trace("stage not loaded");
    }
    if(mouseY > (sHeight/2) + 100){
        if(tHolder.y-50 > - (compHeight-sHeight)){
            Tweener.addTween(tHolder, {y:tHolder.y - 90, time:1,transition:"easeOutCubic"});
        }
        }else if(mouseY < (sHeight/2) - 100){
            if(tHolder.y+50 < 80){
            Tweener.addTween(tHolder, {y:tHolder.y + 90, time:1,transition:"easeOutCubic"});
            }else{
               Tweener.addTween(tHolder, {y:80, time:1,transition:"easeOutCubic"});
            }
        }
    }
}

-J

+2  A: 
stage.addEventListener(Event.MOUSE_LEAVE, function(e:Event):void {});
maxmc
This got me all excited, except that it doesn't register because the stage is set to be 100% of the browser window. I'm not exactly sure if that's the reason it's not working, but it aint.
Jascha
It shouldn't matter if your stage is at 100% or whatever. This event is triggered when the mouse leaves the stage. All you have to do is to stop you Tweens and mouse listeners when the event is triggered. Lot's of tutorials out there, but have a look on this to start : http://blog.zupko.info/?p=3
Theo.T
I guess I figured it wasn't working on account of trying it out with the "publish preview" I'd just set the event to trigger {trace ("off") } and it wasn't coming up. seems to be working now... now I just have to figure out how to implement it in my crappy code.
Jascha
You know what... it works on mouse out... but I still get a funky result when the actual browser looses focus.
Jascha
+2  A: 

Hi,

I suggest detecting the window focus events onblur and onfocus ( http://www.devguru.com/technologies/ecmascript/quickref/evHan_onBlur.html ) in Javascript then sending an enable / disable call through to the SWF file using ExternalInterface ( http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html ) So inside your HTML you might have something like this (assuming swfobject here, but this isn't necessary http://code.google.com/p/swfobject/ ):

swfobject.embedSWF("mySWF", "mySWFId", swfWidth, swfHeight, "10.0.0", "", flashvars, params, attributes);

window.onblur=function () {
    if ( document.getElementById("mySWFId").disableMouseScrolling) {
        document.getElementById("mySWFId").disableMouseScrolling();
    }
}

window.onfocus=function () {
    if ( document.getElementById("mySWFId").enableMouseScrolling ) {
        document.getElementById("mySWFId").enableMouseScrolling();
    }
}

And inside your SWF file some equivalent ExternalInterface code to hook up the methods:

public class MyApplication extends ...
{
    public function MyApplication ():void
    {
        ExternalInterface.addCallback("disableMouseScrolling", disableMouseScrolling);
        ExternalInterface.addCallback("disableMouseScrolling", enableMouseScrolling);
        ...
    }
    private function disableMouseScrolling ():void
    {
    }
    private function enableMouseScrolling ():void
    {
    }
    ...
}

Hope this helps. I've used it with IE8, Firefox 3 and Crome 4.

Regards,

Jotham