Jump to content
Search Community

getting a better grib on throwsPlugin and bitmap masking

icekomo test
Moderator Tag

Recommended Posts

Hello,

I am trying to just take apart one of the demo files you have on the site to better understand how everything works. I got most of it working.. but for some reason my demo will only let me pull down and have it slide back to the stop... it wont allow me to scroll up the list of items. (I thought it had to do with a Y issue, but so far no luck.)

Below is the code, that is almost identical to the example...just not sure what is causing it not to scroll up.... again I'm trying to get a better understanding how this all works for future projects:

 

public class NameContainer extends MovieClip
{
 private var t1:uint,t2:uint,y1:Number,y2:Number,yOverlap:Number,yOffset:Number;
 private var bounds:Rectangle = new Rectangle(0,0,640,825);
 private var blitMask:BlitMask;
 public function NameContainer()
 {
  blitMask = new BlitMask(this,bounds.x,bounds.y,bounds.width,bounds.height,false);
  blitMask.update(null, true);
  blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  blitMask.bitmapMode = false;
 }
 function mouseDownHandler(event:MouseEvent):void
 {
  TweenLite.killTweensOf(this);
  y1 = y2 = this.y;
  yOffset = this.mouseY - this.y;
  yOverlap = Math.max(0,this.height - bounds.height);
  t1 = t2 = getTimer();
  this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
  this.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
 }
 function mouseMoveHandler(event:MouseEvent):void
 {
  //this.mouseChildren = false;
  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)
  {
   this.y = (y + bounds.top) * 0.5;
  }
  else if (y < bounds.top - yOverlap)
  {
   this.y = (y + bounds.top - yOverlap) * 0.5;
  }
  else
  {
   this.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 = this.y;
   t1 = t;
  }
  event.updateAfterEvent();
 }
 function mouseUpHandler(event:MouseEvent):void
 {
  this.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
  var time:Number = (getTimer() - t2) / 1000;
  var yVelocity:Number = (this.y - y2) / time;
  ThrowPropsPlugin.to(this, {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

I have an idea as to why this might be happening.. in the example the text is populated at build.. but for my example.. im trying to use a container (this) and have the content dynamically added, so I think I would have to use the height of (this) somewhere in this code.....

Link to comment
Share on other sites

I see two problems:

 

1) You're creating your BlitMask inside the constructor and the target of the BlitMask is the instance itself. So the constructor hasn't even finished running yet (meaning the object hasn't been fully instantiated) and you're asking BlitMask to capture all its pixels. It's like trying to hug your baby when it is still in the womb (okay, probably a bad example, but you get the idea). You should either create an event listener for when the object is done being instantiated or is added to the stage or something or use a timer or ENTER_FRAME listener to wait a very short amount of time before creating your BlitMask.

 

2) You're referencing this.mouseY on the very object that you're dragging, and then moving it which would affect this.mouseY. It's like a bad feedback loop with a microphone and speakers. I think you probably meant to reference this.parent.mouseY which is much more objective.

  • Like 1
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.
×
×
  • Create New...