Skip to main content
Participating Frequently
April 5, 2010
Question

Can I constrain mouse to loaded swf? (beginner question)

  • April 5, 2010
  • 3 replies
  • 653 views
Hi folks,

I built a movie in flash CS4 based on the tutorial here:
http://www.kirupa.com/developer/flashcs3/detecting_when_mouse_leaves_movie.htmhttp://www.kirupa.com/developer/flashcs3/detecting_when_mouse_leaves_movie.htm

Now if I load this swf into a bigger SWF the mouse is acting in the entire movie as if it were in de loaded swf.

This also happens when I test it (ctrl-enter) and make the resulting box bigger... the mouse will not fade at the border of the swf any more, but at the border of the containing window....)

is there a (easy) way to constrain the mouse behaviour within the box of the loaded swf (like the MOUSELEAVE event triggered when i leave the box of the loaded swf in stead of the entire stage?)

Thanks!

This topic has been closed for replies.

3 replies

MelluwAuthor
Participating Frequently
April 6, 2010

Thanks for your responses!

So if I get both of you correctly, there is no way to do this without changing the embedded .swf?

I have to rewerite parts of that so that the mouse handling is confined in the space of itself?

does this mean that if I ever want to embed a 3rd party swf and there is no coding for it their custom mouse will be all over my container?

in the mean time: back to the drawingboard...

Ned Murphy
Legend
April 6, 2010

Nope, what I offered requires no change to the loaded swf, you can have the main one keep track of where the mouse is relative to the area occupied by the loaded swf.  You just need to know the x/y and width/height of the swf to define that occupied area relative to the main file.

I'm pretty sure what Attaboy offereed also requires nothing be done inside the loaded file, but he'd have to explain that one for you.

MelluwAuthor
Participating Frequently
April 6, 2010

okay!

So I'm a little bit further now...

I restricted the mouse within the containing box by monitoring it's position in de container. thanks for that tip!

that works!

so next step is: How do I get my mouse back? (the swf in the container contains a Mouse.hide and Mouse.show doesn't seem to do anything?

and 2nd is how do I get the MOUSELEAVE function to fire in de contained swf when the containermouse is no longer over the contained swf?

I will check out the Attaboy tip now.. see if I can find more info on that.

AttaBoy2
Inspiring
April 6, 2010

you might want to create a hitTestObject.   http://www.foundation-flash.com/tutorials/as3hittesting/

This is just the first tutorial that came up in my google search so I don't know how good it is.

Ned Murphy
Legend
April 6, 2010

As far as using MOUSE_LEAVE in that scenario, that's something you can test yourself to see if it works or not--though I don't think it will since the stage is defined by the main swf..  But there may be a couple other approaches that could work.  One could be to have a MOUSE_MOVE listener who's handler function tests whether the mouse is within the stage space occupied by the swf--checking the min/max x/y properties thereof.