A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Sprite y based on mouse position?

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    4

    Unhappy Sprite y based on mouse position?

    So I'm working on my portfolio and I got this problem. The code posted scrolls the sprite "cellContainer" based on the position of stage.mouseY. Perfect.

    Problem is that I want stage.mouseY to equal the entire cellContainer height. Kind of like how a small tablet equals a huge monitor. So when stage.mouseY = 0, cellContainer.y = 0 and when stage.mouseY = stage.stageHeight, cellContainer.y = stage.stageHeight - cellContainer.height. Right now, it scrolls, but it takes a while to scroll throught the entire height of cellContainer. I want it to be proportional to stage.mouseY.

    Actionscript Code:
    private function scrollStart(e:Event):void
            {
                cellContainer.y += Math.cos((-stage.mouseY/stage.stageHeight)*Math.PI) * 10;

               
                if (cellContainer.y > 0)
                {
                    cellContainer.y = 0;
                }
               
                if (-cellContainer.y>(cellContainer.height - stage.stageHeight))
                {
                    cellContainer.y = -(cellContainer.height - stage.stageHeight);
                }
                   
            }

    Any help would be appreciated! Thanks!

  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Here's a link to what I would it to resemble:

    http://www.werkstette.dk

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Okay, no one replied, but I figured it out. If anyone is interested, place this inside ENTER_FRAME:
    Actionscript Code:
    var containerY:Number = ((stage.mouseY * (stage.stageHeight - cellContainer.height))/stage.stageHeight);
           
                TweenLite.to(cellContainer, .5, {y:containerY});

  4. #4
    Senior Member Genesis F5's Avatar
    Join Date
    Jan 2002
    Location
    Unallocated memory
    Posts
    1,845
    No one replied, most likely, because this is the non-technical conversation only forum. Please only use the technical forums listed here for technical questions.

    Also, do not put it in ENTER_FRAME. TweenLite has its own ENTER_FRAME event. By using ENTER_FRAME, you're having TweenLite reset itself over and over again, even if the mouse isn't moving. Instead, use MouseEvent.MOUSE_MOVE and make sure it's not checking for a mouse movement globally, but only within the bounds of the gallery preview images.

  5. #5
    Mom said "make me a Mod" el-Ignoramus's Avatar
    Join Date
    Oct 2002
    Location
    Xanadu
    Posts
    1,772
    BURNT.Responsibly = TRUE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center