21 Replies Latest reply on Oct 2, 2009 11:55 AM by mattrichards

    onEnterFrame

    mattrichards
      I have an FLA (attached and code below) in which I am tracking the position of the mouse, and moving an image based on the mouse positions. Pretty standard image scroller really.

       

      I am using onEnterFrame to detect when the mouse is over the image, and hence when to begin scrolling. The problem is, when the SWF pops up in teh Flash Viewer, the image starts scrolling right off the bat, even though the mouse isn't even in the Flash Viewer window.

       

      Any thoughts on how to resolve this?

       

      Matt

       

      controller.onEnterFrame = function(){
      if((this._parent.pics2._x - this._xmouse/30)>(-this._parent.pics2._width+600) && (this._parent.pics2._x - this._xmouse/30) <0){
      //Move the base image
      this._parent.pics2._x -= this._xmouse/30;
      //Move the change images
      this._parent.InnerWal2._x -= this._xmouse/30;
      }
      }
        • 1. Re: onEnterFrame
          mattrichards Level 1

          Update: What it seems to be doing is collecting the mouse's location when the SWF loads and starting to scroll based on that. This is evidenced by the fact that when the mouse is to the far right of the screen when the SWF is launched, the image starts scrolling quickly. If it is father left, it does not start scrolling at launch.

           

          Is there some way to prevent it from doing this? Or, perhaps there is a better way to determine when the mouse is actually over the image?

           

          Matt

          • 2. Re: onEnterFrame
            Ned Murphy Adobe Community Professional & MVP

            It depends on what you have going on with the image, but you could have a rollover for the image's container movieclip that ignites the enterframe activity and a rollout that deletes it.

             

            You might also just determine the _x and _y boundaries of the image and check if the mouse is wiithin those boundaries in your enterframe function

            • 3. Re: onEnterFrame
              mattrichards Level 1

              Ned,

               

              Thanks for the reply. Basically, I just have a very long image that I am scrolling across the stage by modifying it's X property based on the mouse location. (the fla was actually attached to the original post if you are curious to see it)

               

              Might you have any ideas as to where I might find some example code detailing either of the methods you have suggested? I will give them a go myself, but it might be easier to see how it has been done elsewhere. I'm pretty new to actionscript.

               

              Thanks again for all your help.

               

              Matt

              • 4. Re: onEnterFrame
                Ned Murphy Adobe Community Professional & MVP

                What's the fun of being given the answers!?  You should try things... it's the best way to learn what works and what doesn't.

                 

                For whatever reason I am unable to unzip zipped files that get attached to these forums, so I don't even bother trying anymore when I see .zip...  and if it happens to be a CS4 file, I don't have CS4.

                 

                I don't know how you have things set up or what's what, so this example might be way off, but here's the first....  I assume pics2 is the scrolling movieclip, though I may be wrong...

                 

                Assign rollover and rollout code to the movieclip that is supposed to scroll...

                 

                pics2.onRollOver = function(){

                     pics2.onEnterFrame = function(){

                          // your scroll control code

                     }

                }

                 

                pics2.onRollOut = function(){

                     delete pics2.onEnterFrame;

                }

                 

                Here's the second approach... it just checks to see if the mouse is over the scrolling mc based on its position... it starts in the enterframe function you already have...

                 

                controller.onEnterFrame = function(){
                     if(_ymouse > pics2._y  && _ymouse < pics2._y+pics2.height && _xmouse > 0 && _xmouse < Stage.width){
                           // your scroll control code
                     }
                }
                • 5. Re: onEnterFrame
                  AttaBoy2 Level 4

                  For me the problem you mention only happens when testing.  If I run the published swf the problem isn't there.

                   

                  Thanks for the code example.

                  • 6. Re: onEnterFrame
                    mattrichards Level 1

                    Ned,

                     

                    Thank you so much for this. I absolutely agree that giving it a go myself is best, especially long term. The CS degree in me wants to do only that, but the deadline wants otherwise.

                     

                    I'll take a good look at this code tomorrow morning. Again, much appreciated.

                     

                    Matt

                    • 7. Re: onEnterFrame
                      mattrichards Level 1

                      Jim,

                       

                      It's interesting to hear that you aren't seeing it when you run the SWF directly. Is it opening in Flash Player? What version?

                       

                      Also, when you double-click the SWF file to open it, does the Flash Player open to the right of the window from which you launched the SWF? If so, there would be no scrolling. If youhave the SWF icon to the right of the Flash Player window when it opens, it will start scrolling right off the bat.

                       

                      Matt

                      • 8. Re: onEnterFrame
                        AttaBoy2 Level 4

                        I see what you mean.  Maybe you should use the hitTestPoint to be sure the mouse is over the swf.  Maybe if hitTestPoint=false stop the scroll.

                        • 9. Re: onEnterFrame
                          mattrichards Level 1

                          Jim,

                           

                          I'll take a look at that as well. Thanks so much.

                           

                          Matt

                          • 10. Re: onEnterFrame
                            AttaBoy2 Level 4

                            what is controller?

                            • 11. Re: onEnterFrame
                              AttaBoy2 Level 4

                              Forget my last couple of entries.  I just now realize this is AS2.  I was wondering why this code seemed so odd.

                              • 12. Re: onEnterFrame
                                mattrichards Level 1

                                Guys,

                                 

                                Thanks for the suggestions. Unfortunately, they yield the same problem. The flash player sees the mouse as being on the image when it is outside of the flash player application window.

                                 

                                Basically, I have this very long image that I am scrolling across the stage. So, there is quite a bit of image area off the stage and to the right. The player "sees" this image content, and reports the mouse as being over the image, even though the image and the mouse are outside of the flash player window.

                                 

                                A RollOver or EnterFrame on the images themselves just don't work. I really need to figure out a way to check to see if the mouse is within the stage, or inside of the flash player window or SWF.

                                 

                                Matt

                                • 13. Re: onEnterFrame
                                  mattrichards Level 1

                                  I'm starting to think that I will have to rewrite this in AS3 so that I can take advantage of MOUSE_LEAVE and MOUSE_MOVE. Problem is that I've never worked with AS3, and I'm not sure my deadline will allow the learning and rewrite.

                                   

                                  Perhaps there is a way to draw a movie clip just for this purpose and detect the mouse's presence over that, instead of over the stage generally...

                                   

                                  Matt

                                  • 14. Re: onEnterFrame
                                    AttaBoy2 Level 4

                                    hummm... so maybe you should test to see if the mouse is over the stage.

                                    • 15. Re: onEnterFrame
                                      mattrichards Level 1

                                      Indeed, I am trying to figure that out now.

                                      • 16. Re: onEnterFrame
                                        mattrichards Level 1

                                        From what I've tried, and what I've read, it seems like tracking the mouse on and off stage in AS2 is not particularly reliable. AS2 does not have a built in mechanism for this (as AS3 does), the it appears that he most common solution it to try to detect onMouseOut events over movie clips at the edges of the stage. Mouse speed is an issue in paticular here. This approach can be supplemented with the use of a timer, or tracking the velocity of the mouse, but at this point I might as well start thinking about an AS3 re-write.

                                         

                                        If anyone has come up with something better that this AS2 approach, let me know. If not, AS3 here I come...

                                         

                                        Matt

                                        • 17. Re: onEnterFrame
                                          mattrichards Level 1

                                          A nice solution for SWFs in the browser is here. Unfortuantely I am working with the Flash Player on the desktop.

                                           

                                          http://www.jackleaman.co.uk/examples/outofflash.htmlhttp://board.flashkit.com/board/showthread.php?p=4208370&posted=1#post4208370

                                           

                                          From the author:

                                           

                                          note the javascript in the html file
                                          MyToggle variable returns 1 or 2 (in Flash - 1, out - 2)
                                          incorporate the variable within your onEnterFrame / if(condition)

                                          ps ..
                                          cut the <script> from the html file
                                          update the publish settings to Flash 8
                                          paste the <script> back into the new html file
                                          reset the object id and embed name to gMovie

                                          • 18. Re: onEnterFrame
                                            AttaBoy2 Level 4

                                            why not create a MovieClip over everything else with either the dimensions

                                            of the stage or the dimensions of the image on stage, set the _alpha to 0,

                                            and use that for mouse over mouse out stuff.

                                            • 19. Re: onEnterFrame
                                              mattrichards Level 1

                                              I've found that the presence of the new movieclip interferes with the scrolling. Also, from what I understand, even if I get it working, and the mouse leaves the movieclip quickly, the onmouseout event is not captured.

                                               

                                              Matt

                                              • 20. Re: onEnterFrame
                                                AttaBoy2 Level 4

                                                You should be able create a function that scrolls MovieClip B when you roll

                                                over MovieClip

                                                I'm pretty sure AS2 isn't that limited.

                                                • 21. Re: onEnterFrame
                                                  mattrichards Level 1

                                                  Thanks Jim. I'll take a better look at it.