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 6640925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:45:03+00:00 2026-05-25T23:45:03+00:00

This is the class I am trying instantiate into my main class: public class

  • 0

This is the class I am trying instantiate into my main class:

public class Character extends Sprite {

    [Embed(source='../lib/front1.svg')]
    private var front1Class:Class;
    private var crosshair:Sprite = new front1Class ();

    public function Character() {
        trace("started");
        Mouse.hide();

        crosshair.scaleX = 5;
        crosshair.scaleY = 5;
        this.addChild(crosshair);

        stage.addEventListener(Event.ENTER_FRAME, MrEveryFrame);
        stage.addEventListener(MouseEvent.CLICK, click);
    }


    private function click(evt:MouseEvent):void {
        trace("clicked @ " + evt.stageX + "," + evt.stageY);

    }
    public function MrEveryFrame(e:Event):void
    {
        crosshair.x = mouseX - 15;
        crosshair.y = mouseY - 15;


    }

}

When I set it to the document class, it works fine.

However… when I make THIS my document class and try to call it from there:

public class Shell extends Sprite
{


    private var character:Sprite = new Character ();


    public function Shell() 
    {

        addChild(character);


    }


}

It breaks, and no longer shows the sprite object (though it does erase the mouse pointer).

What’s the deal here? You can’t instantiate custom sprite or movieclip classes into a DisplayObject class???

  • 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-25T23:45:04+00:00Added an answer on May 25, 2026 at 11:45 pm

    The stage is null in the constructor. That only works when your class is the Document Class, as you found out yourself. So change your constructor like this:

    public function Character() {
        trace("started");
        Mouse.hide();
    
        crosshair.scaleX = 5;
        crosshair.scaleY = 5;
        this.addChild(crosshair);
    
        addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    }
    
    private function onAddedToStage(event:Event):void
    {
    
        stage.addEventListener(Event.ENTER_FRAME, MrEveryFrame);
        stage.addEventListener(MouseEvent.CLICK, click);
    }
    

    Adding the listener will access the stage only after the stage is known, and it’s no longer null

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

Sidebar

Related Questions

I've trying to achieve something like this: class Base { public: Base(string S) {
I'm trying to compile a POCO with this code public class MenuItem { public
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I'm trying to instantiate a class using the Constructor.newInstance() method but am running into
im trying to do this: class Event < ActiveRecord::Base belongs_to :previous_event has_one :event, :as
I'm trying to to use this class http://robbyonrails.com/articles/2005/05/11/parsing-a-rss-feed but am not sure where to
What I am trying to achieve is something like this: class object: def __init__(self):
i am trying to compile this very simple piece of code class myList {
I am trying to use this in my page class. I only just started
I'm trying to use: // this is a BreakHistory class from the ADO.NET Data

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.