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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:41:33+00:00 2026-06-08T09:41:33+00:00

I have a game engine class that creates my main character instance and game

  • 0

I have a game engine class that creates my main character instance and game border instance when the game is loaded like so:

public class Engine extends MovieClip
{
     var char:Char = new Char(stage);
     stage.addChildAt(char, 1);

     var border1:Border = new Border();
     stage.addChild(border1);

    }

I would like to access the variable border1 that was created in the Engine class inside of my Char class. Is this possible, and if so, how would I do it?

I’ve tried changing the code so border1 is static like so

static var border1:Border = new Border();

But then I get

error 1012: The static attribute may be used only on definitions inside a 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-06-08T09:41:36+00:00Added an answer on June 8, 2026 at 9:41 am

    You could do this a few ways.

    1.  Create the border1 and char instances in reverse order and pass the border1 to the char instance to maintain a reference.
    
    var border1:Border = new Border();
    stage.addChild(border1);
    
    var char:Char = new Char(stage, border1);
    stage.addChildAt(char, 1);
    
    // Char consructor
    
    public function Char(target:DisplayObjectContainter, border:Border):void {
        ...
        this._border = border;
    }
    
    // Now you have a reference to the border1 instance within your char instance.
    

    You could also do this without passing the border1 instance to the constuctor, and instead just add a method that sets this property.

    public function setBorder(border:Border):void {
        this._border = border;
    }
    
    // OR
    
    public function set border(border:Border):void {
        this._border = border;
    }
    

    Another option would be to make the Engine instance maintain a reference to the border and allow communication through the Engine instance. For example,

    public class Engine extends MovieClip {
    
        public var char:Char;
        public var border1:Border;
    
        public function Engine():void {
            char = new Char(stage);
            stage.addChildAt(char, 1);
    
            border1 = new Border();
            stage.addChild(border1);
        }
    

    Now, if the char instance has a reference to the engine instance, then the border instance can be referenced by myEngineInstance.border1.

    Or you can make the border instance static. Making it static would allow for code inside of the Char instance like:

    Engine.border1.<whatever>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my game engine I have a State class that represents the game world
I am writing a basic game engine and have an abstract class that represents
I have a game engine that uses OpenGL for display. I coded a small
I'm working on a game engine in C++ and I have methods like setColour
I have a clojure project that uses the slick 2d game engine that I
I have a singleton instance that is referenced throughout the project which works like
I have written a game engine in C++, however I would like to package
Suppose I have an component based game engine, and in that engine I have
So in my game, every 'enemy' movieclip creates a textfield that represents the name
Consider a game engine that utilizes a scene . Now, a scene can have

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.