Jump to content
GreenSock

PapaDeBeau

ThrowProps - Strange Space on Top or left in APPS

Recommended Posts

I am getting strange spaces in my Android at the top, like ten pixels of white space when I use throwprops and I am getting the same white space on the iphone on the left, about 15 pixels.

 

Here is my code below. What am I missing?  I just noticed I have the imports in there twice but I don't think that should matter. This is my first time I actually got throwprops to work on an App. I am very excited to see what can be done.



flagButton.width = stage.stageWidth - 50;
flagButton.scaleY = flagButton.scaleX;
flagButton.x = stage.stageWidth/2 - flagButton.width/2;

import com.greensock.*;
import com.greensock.plugins.*;
import com.greensock.easing.*;
 import com.greensock.events.LoaderEvent;
    import com.greensock.loading.*;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.utils.getTimer;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import com.greensock.TweenLite;
    import com.greensock.easing.Strong;
    
TweenPlugin.activate([ThrowPropsPlugin]);

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.geom.Rectangle;
import flash.utils.getTimer;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);

var bounds:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
var mc:Sprite = flagButton;
addChild(mc);
//setupTextField(mc, bounds);
var blitMask:BlitMask = new BlitMask(mc, bounds.x, bounds.y, bounds.width, bounds.height, false);

var t1:uint, t2:uint, y1:Number, y2:Number, yOverlap:Number, yOffset:Number;

blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function mouseDownHandler(event:MouseEvent):void {
    TweenLite.killTweensOf(mc);
    y1 = y2 = mc.y;
    yOffset = this.mouseY - mc.y;
    yOverlap = Math.max(0, mc.height - bounds.height);
    t1 = t2 = getTimer();
    mc.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    mc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}

function mouseMoveHandler(event:MouseEvent):void {
    var y:Number = this.mouseY - yOffset;
    //if mc's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior)
    if (y > bounds.top) {
        mc.y = (y + bounds.top) * 0.5;
    } else if (y < bounds.top - yOverlap) {
        mc.y = (y + bounds.top - yOverlap) * 0.5;
    } else {
        mc.y = y;
    }
    blitMask.update();
    var t:uint = getTimer();
    //if the frame rate is too high, we won't be able to track the velocity as well, so only update the values 20 times per second
    if (t - t2 > 50) {
        y2 = y1;
        t2 = t1;
        y1 = mc.y;
        t1 = t;
    }
    event.updateAfterEvent();
}

function mouseUpHandler(event:MouseEvent):void {
    mc.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    mc.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    var time:Number = (getTimer() - t2) / 1000;
    var yVelocity:Number = (mc.y - y2) / time;
    ThrowPropsPlugin.to(mc, {throwProps:{
                                 y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:300}
                             }, onUpdate:blitMask.update, ease:Strong.easeOut
                            }, 10, 0.3, 1);
}



Link to comment
Share on other sites

Pretty tough to diagnose without having your FLA to publish and see how it's built, but I wonder if your flagButton has some extra space at the top or something that has alpha:0 up above (inside) it or a rotated item that's causing the extra pixels at the top. Feel free to adjust the "bounds" coordinates to compensate. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×