shaking the stage

cookiejest
cookiejest used Ask the Experts™
on
I want to shake the main stage when a frame is entered inside an MC. This is for a game and i intend to have it so when a bomb explodes, the stage shakes quickly(not the browser window) and then stops so it randomly moves to see small parts of stuff that is outside the stage briefly. Is there a tutorial or something that can show me how to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2008
Commented:
step 1:
Copy following two function on _root of your FLA
//==============
function StartShaking()
{
      _root.initX = _level0._x;
      _root.initY = _level0._y;
      _root.initAlpha = _level0._alpha;
      _root.initRotation = _level0._rotation;
      _root.times = 40;
      _root.intId = setInterval(_root, "shakeStage", 20);
}
function shakeStage()
{

      if (_root.times>0)
      {
            a = 3;
            b = 6;
            c = 9;
            _level0._x = random(a);
            _level0._y = random(b);
            _level0._alpha = 50+random(45);
            _level0._rotation = random(a);
            _root.times--;
      }
      else
      {
            _level0._x = initX;
            _level0._y = initY;
            _level0._alpha = initAlpha;
            _level0._rotation = initRotation;
            clearInterval(_root.intId);
      }
}

//================

step2:
Now call function "StartShaking" to start shaking.. for exmaple: call it on a button press:
example code:

//-------------
btn.onPress = function()
{
      _root.StartShaking();
};
//-------------


- Aneesh Chopra

Author

Commented:
nothings moving :s
Top Expert 2008

Commented:
what flash version are you using..?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Dushan De SilvaTechnology Architect

Commented:
Its working. Buton is shaking.
Copy step 01 to first frame. Copy step 02 to the button.
eg:
on (release) {
      _root.StartShaking();
}

BR Dushan

Author

Commented:
mx2004
Top Expert 2008

Commented:
you should export for Flash Player 7 with AS 2.0, and code should work fine..

- Aneesh Chopra

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial