Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:19:57+00:00 2026-06-15T11:19:57+00:00

This question is related to ActionScript 3.0 and Flash CS6 I am trying to

  • 0

This question is related to ActionScript 3.0 and Flash CS6

I am trying to make an object shake a bit in a certain for some seconds. I made it a “movieclip” and made this code:

import flash.events.TimerEvent;

var Machine_mc:Array = new Array();

var fl_machineshaking:Timer = new Timer(1000, 10);
fl_machineshaking.addEventListener (TimerEvent.TIMER, fl_shakemachine);
fl_machineshaking.start ();


function fl_shakemachine (event:TimerEvent):void {


 for (var i = 0; i < 20; i++) {

  Machine.x += Math.random() * 6 - 4;
  Machine.y += Math.random() * 6 - 4;
 }

}

When testing the movie I get multiple errors looking exactly like this one:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Historieoppgave_fla::MainTimeline/fl_shakemachine()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

Also, the object doesnt shake, but it moves steadily upwards to the left a bit every tick.

To the point:
I wish to know how I stop the script after the object is not in the stage/scene anymore and also how to make it shake around, as I do not see what is wrong with my script, please help, thank you ^_^

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:19:58+00:00Added an answer on June 15, 2026 at 11:19 am

    You have to remember the original start position and calculate the shake effect from that point. This is my shake effect for MovieClips. It dynamically adds 3 variables (startPosition, shakeTime, maxShakeAmount) to it. If you use classes, you would add them to your clips.

    import flash.display.MovieClip;
    import flash.geom.Point;
    
    function shake(mc:MovieClip, frames:int = 10, maxShakeAmount:int = 30) : void 
    {
        if (!mc._shakeTime || mc._shakeTime <= 0)
        {
            mc.startPosition = new Point(mc.x, mc.y);
            mc._shakeTime = frames;
            mc._maxShakeAmount = maxShakeAmount;
            mc.addEventListener(Event.ENTER_FRAME, handleShakeEnterFrame);
        }
        else
        {
            mc.startPosition = new Point(mc.x, mc.y);
            mc._shakeTime += frames;
            mc._maxShakeAmount = maxShakeAmount;
        }
    }
    
    function handleShakeEnterFrame(event:Event):void
    {
        var mc:MovieClip = MovieClip(event.currentTarget);
        var shakeAmount:Number = Math.min(mc._maxShakeAmount, mc._shakeTime);
        mc.x = mc.startPosition.x + (-shakeAmount / 2 + Math.random() * shakeAmount);
        mc.y = mc.startPosition.y + (-shakeAmount / 2 + Math.random() * shakeAmount);
    
        mc._shakeTime--;
    
        if (mc._shakeTime <= 0)
        {
            mc._shakeTime = 0;
            mc.removeEventListener(Event.ENTER_FRAME, handleShakeEnterFrame);
        }
    }
    

    You can use it like this:

    // shake for 100 frames, with max distance of 15px
    this.shake(myMc, 100, 15);
    

    BTW: In Flash, you should enable ‘permit debugging’ in your ‘publish settings‘ to have more detailed errors. This also gives back the line numbers where your code is breaking.


    update:
    Code now with time / maximum distance separated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to the one I asked here . I'm trying to
This question is related to another question of mine. Thanks to some help I
This question is related to How to make consistent dll binaries across VS versions
This question is related to my another question- boost::bind return a function object which
This question is related to Does this C++ static analysis rule make sense as
This question is related to my original question I am trying to follow Ken's
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question is related to another question, where I wanted to define a custom
This question is related to my previous post Image Processing Algorithm in Matlab in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.