• Xhanch - WP Manga - Have your own automated manga reader website

Action Script – Walled Bouncing Ball

This Flash script will result in animation of a ball that will be bounced when it hit a barrier/wall. The area is a rectangle so that the ball will keep bouncing inside the rectangle. You can even move the ball. Click on it and hold to stop the bouncing and then release the mouse to continue bouncing. What we need to produce the animation is just a movie clip an a simple script.

Preview

Source Code

//By    : Xhanch Studio
//URL   : http://xhanch.com/action-script-walled-bouncing-ball/

_animate = true;
//Horizontal Speed
_vx = 2;
//Vertical Speed
_vy = 2;

//Bouncing Area
//Left
_bl = 50;
//Right
_br = 500;
//Top
_bt = 50;
//Bottom
_bb = 350;

this.onEnterFrame = function(){
    if (_animate){
        //Set the new ball position
        mc_ball._y += _vy;
        mc_ball._x += _vx;

        //Area limitation checker
        if (mc_ball._y > _bb)
            _vy = Math.abs(_vy)*-1;
        else if (mc_ball._y < _bt)
            _vy = Math.abs(_vy);

        if (mc_ball._x > _br)
            _vx = Math.abs(_vx)*-1;
        else if (mc_ball._x < _bl)
            _vx = Math.abs(_vx);
    }
}

//On press event, the ball will stop bouncing and drag mode is on
mc_ball.onPress = function(){
    _animate = false;
    mc_ball.startDrag(true);
}

//On release event, the ball will start bouncing and drag mode is off
mc_ball.onRelease = function(){
    _animate = true;
    mc_ball.stopDrag();
}

Download

Click here to download the source code


Leave a Reply

  • NOTICE

    Xhanch Studio is finally online after successfully moved from shared hosting to our own VPS Hosting.

    Please note that our primary email admin@xhanch.com is not functioning yet. So, please send your emails to xhanch@gmail.com for the moment until we resolve this issue.

    Regards, Xhanch Studio
  • Sponsored Ads

    WalkNote.com - A Place to Share, Have Fun and Get Connected Place you ad here
  • PayPal Verified

    Happy with our free services? You may donate us. Thanks!

    Donate
  • Latest Tweets

    Here are our recent tweets:

    • @xhanch Your a legend!!! I have just used the first part of the code so the links are a different colour and it looks fab, Thanks! - posted on 3 days ago via Tweetie for Mac

    • Xhanch - My Twitter 2.0.2 is released. Some minor fixings - posted on 3 days ago via web

    • We have finished the website migration to a VPS server - posted on 3 days ago via web

    • @Bunglenick put this code to custom CSS: {xmt_id}.xmt ul li.tweet_list{color:#ffffff} {xmt_id}.xmt ul li.tweet_list a{color:#ffffff} - posted on 3 days ago via web

    • @xhanch Hi there, how do I go about changing the colour of the text in your twitter app? Its black but I need white. - posted on 5 days ago via Tweetie for Mac