Jump to content


throwprops interferring with stage listeners?

Recommended Posts

Hey everybody, Carl & Jack in particular

So heres the cause of my insomnia.

Making a basic fish pond game, (like koi pond) in flash. I have got throwprops scolling working beautifully on the background (called "mc"), which sits on the stage. The stage is 800px by 480px, the background mc is 2400 by 480.

I have fish swimming about, which swim to where the user last clicked.

Long story short, everything is working perfectly, except if the user clicks to the right of stage, (eg: y>800), it won't work, the fish will not swim past 800, even though i can scroll across, they will not follow,


But in the dimensions of the stage, they work a treat.

Its as if throwprops is sliding the stage to left as well?

there is a lot of code for this one, so i'll just show whats relevant, let me know if theres something you want to see,


Throwprops on background ("mc"):


//var bounds:Rectangle = new Rectangle(0, 0, 800, 480);

ThrowPropsPlugin.track(mc, "x");
mc.addEventListener(MouseEvent.MOUSE_DOWN, bg2down);
function bg2down(event:MouseEvent):void {
    mc.startDrag(false, new Rectangle(bounds.x, 0, -1600, 0));
    mc.stage.addEventListener(MouseEvent.MOUSE_UP, bg2up);
function bg2up(event:MouseEvent):void {
    mc.stage.removeEventListener(MouseEvent.MOUSE_UP, bg2up);
    var xOverlap:Number = Math.max(0, mc.width - bounds.width);
    ThrowPropsPlugin.to(mc, {ease:Strong.easeOut, throwProps:{x:{max:bounds.left, min:bounds.left - xOverlap, resistance:200}}}, 10, 0.25, 1);

Aquire MouseX, MouseY for fish ("redfish")

    private function updatePosition():void
            // check if mouse is down
            if (_isActive)
                // update destination
                _destinationX = stage.mouseX;
                _destinationY = stage.mouseY;
                // update velocity
                _vx += (_destinationX - this.x) / _moveSpeedMax;
                _vy += (_destinationY - this.y) / _moveSpeedMax;
                // when mouse is not down, update velocity half of normal speed
                _vx += (_destinationX - this.x) / _moveSpeedMax * .25;
                _vy += (_destinationY - this.y) / _moveSpeedMax * .25;
            // apply decay (drag)
            _vx *= _decay;
            _vy *= _decay;
            // if close to target, slow down turn speed
            if (getDistance(_dx, _dy) < 50)
                _trueRotation *= .5;
            // update position
            this.x += _vx;
            this.y += _vy;

Any help/suggestions/advice would be very appreciated,
Thanks everybody.
Happy programming :]

Link to comment
Share on other sites


It's hard to visualize what might be happening here. Please zip up a simplified fla and post it here ( without the greensock files )



Link to comment
Share on other sites

Thanks for the demo, very helpful, and very cool too ;)


The problem is that the coordinates of the fish are relative to their parent element (mc).

When you were telling the fish where to go you were using the mouse position relative to the stage so you could only generate values


x: 0 to 800

y: 0 to 480


But the fish need to swim to an x of 2400 (full width of mc)


When you clicked on the stage and generated a value of 800, the fish were swimming to x:800 but that x value was relative to the origin of mc (the parent of the fish). If you had thrown mc to the left (-x value) chances are you wouldn't see the fish.


Try changing the following lines in redfish.as (line 114-115)

// update destination
_destinationX = stage.mouseX;
_destinationY = stage.mouseY;


// update destination
_destinationX = this.parent.mouseX;
_destinationY = this.parent.mouseY;
  • Like 1
Link to comment
Share on other sites

Whatever you're getting paid Carl, it's not enough.


Thankyou thankyou thankyou


i tried mc.this.mouseX, but ofcourse it didn't like it, so i created a class for mc thinking it would be recognised then...


I am new to the whole class system, have always kept code in the timeline, after hearing about how thats bad practice, and how many advantages there are in class files, classes are obviously the way to go.


Thankyou for putting it so simply with such a great explanation,

Thanks again Carl,




  • Like 1
Link to comment
Share on other sites

Glad it worked. Thanks for the kind words.


FWIW I had the same headaches switching over to class-based code. 

Stick with it, in the end it definitely helps keep things organized.

  • 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.