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

  • Home
  • SEARCH
  • 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 6745517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:53+00:00 2026-05-26T12:12:53+00:00

In my Flash program, I am trying to run a function within an object.

  • 0

In my Flash program, I am trying to run a function within an object. The object uses a class called “SkullDemon.as.” The function I am trying to run is called “moveSkullDemon();” this function is coded within the “SkullDemon.as” class.

My main document class is “TME2d_Main.as.” Within that file I create an instance of the Skull Demon class like this:

        public var skullD1b:SkullDemon;
        skullD1b = new SkullDemon();
        skullD1b.x = 2990.75;
        skullD1b.y = 836.95;
        skullDemonContainer.addChild(skullD1b);

The ‘skullDemonContainer’, which stores the SkullDemon instances, is placed into another container, called ‘envContainer,’ which is added to the screen using this line of code:

        this.addChild(envContainer);

The SkullDemon instance is created and loads onto the screen just fine. The problem occurs when I try to run any function within the SkullDemon class.

As mentioned before, I try to call the ‘SkullDemon.moveSkullDemon()’ function for the ‘skullD1b’ instance. For now, the ‘moveSkullDemon()’ function just moves the SkullDemon object to the left.

I tried calling this function from the SkullDemon’s constructor function, but that does not work. In fact, any code written within the SkullDemon’s constructor is not executed when a Skull Demon object is created. I have tried to create an EventListener within the SkullDemon class that calls ‘moveSkullDemon(),’ but that does nothing.

I have tried the following methods to get the ‘moveSkullDemon()’ function to run:

1: Calling ‘moveSkullDemon()’ from ‘TME2d_Main’ like this:

skullD1b.moveSkullDemon();

But this brings up an error (#1006), saying that ‘moveSkullDemon’ is not a function.

2: Doing the same thing as #1 except that I have no parenthesis within the function call:

skullD1b.moveSkullDemon;

3: Creating an EventListener within ‘TME2d_Main’ for the ‘skullD1b’ instance that calls its ‘moveSkullDemon’ function:

skullD1b.addEventListener(Event.ADDED, skullD1b.moveSkullDemon);

This brings up another error: “Error #2007: Parameter listener must be non-null.” It also constantly finds a “null” reference error:

    "1009: Cannot access a property or method of a null object reference.
    at classes::TME2d_Main/controlPlayer()"

I do not know why this problem refers to the ‘controlPlayer()’ method, as it does not involve the Skull Demon instance at all. ‘controlPlayer()’ is called through an EventListener with this code within ‘TME2d_Main’:

player.addEventListener(Event.ENTER_FRAME, controlPlayer);

4: Creating an EventListener for the ‘SkullDemonContainer’ that calls the move function:

skullDemonContainer.addEventListener(Event.ADDED, skullD1b.moveSkullDemon);

This brings up the same error as in #3.

I have been having this problem for a few days now and do not know what is causing it. Here is my code within the ‘moveSkullDemon()’ function:

        public function moveSkullDemon() {
        trace("skull demon moving!");

        this.x -= 5;

        // If the Player has not hit the 'floor,' increase his falling 
            //speed
        if (! floor.hitTestPoint(this.x, this.y, true)) {
            this.y += this.sdGravity;
            // The Skull Demon is not on the ground when he's not touching it
            sdOnGround = false;
        }

        // Increase the 'sdYVel' variable so that the Skull Demon will fall 
            // progressively faster down the screen. This code technically
            // runs "all the time" but in reality it only affects the Skull Demon
            // when he's off the ground.
        sdYVel += sdGravity;            

        // Increase the Skull Demon's 'y' coordinate by the 'sdYVel' value
        if (! sdOnGround) {
            this.y += sdYVel;
        }
    }

Thanks for any help you may offer.

  • 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-05-26T12:12:54+00:00Added an answer on May 26, 2026 at 12:12 pm

    If I understand right, you are attempting to dispatch an event against your display object, therefore calling a function?

    When you instantiate your skull demon object, add an event listener for the type of event you wish to handle. For example, if you created a “DemonEvent” class:

    // instantiate and add event listener:
    skullD1b = new SkullDemon();
    skullD1b.addEventListener(DemonEvent.MOVE, moveDemonHandler);
    

    When you want to call the “moveDemonHandler” function, you dispatch an event against the object:

    // do call this event listener, dispatch an event
    // against the object
    skullD1b.dispatchEvent(new DemonEvent(DemonEvent.MOVE));
    

    You can place code within the event handler, or call your function from the event handler code:

        protected function moveDemonHandler(event:DemonEvent):void
        {
            moveSkullDemon();
        }
    
        protected function moveSkullDemon():void
        {
            // ... your code here.
        }
    

    Example “DemonEvent” if you need:

    package
    {
        import flash.events.Event;
    
        public class DemonEvent extends Event
        {
    
            public static const MOVE:String = "MOVE";
    
            public function DemonEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
            {
                super(type, bubbles, cancelable);
            }
    
        }
    }
    

    UPDATE

    Based upon your comment, it sounds like you are determining the best place to put code to move your object. Your skull demon could move itself, or since your TME2d_Main class adds the skull demon, positions it initially, and because you need to hit test against a floor, it might make more sense to put that logic in the TME2d_Main class.

    This example doesn’t use events; however, hopefully helps you get started. Let me know if you’d rather have an example that uses events instead.

    here are two classes as an example implementation:

    TME2d_Main.as

    package
    {
        import flash.display.Sprite;
        import flash.events.Event;
    
        public class TME2d_Main extends Sprite
        {
            /** skull demon instance */
            public var skullD1b:SkullDemon;
    
            /** floor */
            public var floor:Sprite;
    
            /** constructor */
            public function TME2d_Main()
            {
                super();
    
                // best if implemented on addedToStage
                skullD1b = new SkullDemon();
                skullD1b.x = stage.stageWidth * 0.5;
                skullD1b.y = 1;
                addChild(skullD1b);
    
                // listen for enter frame
                addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            }
    
            /** every frame, move skull demon */
            protected function enterFrameHandler(event:Event):void
            {
                // call local function of this class
                moveSkullDemon();
            }
    
            protected function moveSkullDemon():void
            {
                // since this TME2d_Main class defined and positioned
                // skullD1b, it probably makes sense for this class
                // to continue positioning it, especially if you need to
                // hit test again a floor, which is probably also defined
                // in this class?
                if (skullD1b.hitTestObject(floor))
                {
                    // skull is on floor 
                    skullD1b.sdOnGround = true;
    
                    // end animation
                    removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                }
                else
                {
                    // otherwise, skull is in air and falling
                    skullD1b.y *= skullD1b.sdYVel;
                }
            }
    
            // if you wanted to have skull demon
            // move itself, you would call:
            //
            //     skullD1b.moveSkullDemon()
            //
            // ...but make sure that function exists
            // in SkullDemon class.
    
        }
    }
    

    SkullDemon.as

    package
    {
        import flash.display.Sprite;
    
        public class SkullDemon extends Sprite
        {
    
            /** acceleration factor */
            public var sdYVel:Number = 1.05;
    
            /** whether skull demon is on ground */
            public var sdOnGround:Boolean = false;
    
            /** constructor */
            public function SkullDemon()
            {
                super();
            }
    
            // if you want SkullDemon to move itself,
            // make sure you define a moveSkullDemon function:
            //
            //      public function moveSkullDemon():void
            //      {
            //      }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bought this program that created a pretty nice imageuploader flash script however I
I'm having a hard time describing a Flash program that uses a sort of
I'm trying to write a program that will run a program on a remote
I have been trying to get a simple networking test program to run with
I trying to learn how to program in Adobe Flash Professional CS5. However i
I am trying to run a shell from my python program. I have used
Hi Im trying to develop a C# program to scrape the urls of flash
I have a flash program that loads movie clips dynamically and sometimes they want
I have a Flash program that loads AS2 and AS3 SWF files dynamically with
I'm looking to use procedurally-generated sound and music in a Flash program I'm writing.

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.