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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:46:35+00:00 2026-05-17T06:46:35+00:00

In an attempt to organize my code, I’m trying to split up my (lengthy)

  • 0

In an attempt to organize my code, I’m trying to split up my (lengthy) main controller class into separate files, but my new files must still have access to the variables and functions of the main controller class.

I’m trying to cut and paste code from my controller class into a new class/file, allowing the controller class to call the new class, and allowing the new class to have access to the controller class’s properties and function.

Assuming I’m not totally bludgeoning appropriate design patterns, below is my unsuccessful attempt at accomplishing this task:

package
{   
import flash.display.Sprite;
import flash.events.Event;

public class Test extends Sprite
    {
    public var myString:String;

    public function Test()
        {
        if  (stage)
            init(null);
            else
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

    private function init(evt:Event):void
        {
        if  (hasEventListener(Event.ADDED_TO_STAGE))
            removeEventListener(Event.ADDED_TO_STAGE, init);

/////////////// MOVE COMMENTED CODE TO NEW FILE ///////////////////////
//      
//      //Assign The String A Value
//      myString = "Hello world";
//      
//      //Draw A Blue Square
//      var sq:Sprite = new Sprite();
//      sq.graphics.beginFill(0x0000FF);
//      sq.graphics.drawRect(10, 10, 100, 100);
//      sq.graphics.endFill();
//      super.addChild(sq);
//      
//      //Call Tracer Function
//      tracer();
//
//////////////////////////////////////////////////////////////////////

        //Call pasted method in NewFile.as
        NewFile.myNewFunction();     // <- this doesn't work
        }

    public function tracer():void
        {
        trace(myString);
        }
    }
}

new file doesn’t have access to the Controller class – doesn’t work. how can i write the new file so that it does have access to the properties, functions, stage, etc. of the Controller class, as if its code was never removed and is still in its original place.

package
{   
public class NewFile
    {
    public static function myNewFuntion():void
        {
        //Assign The String A Value
        myString = "Hello world";

        //Draw A Blue Square
        var sq:Sprite = new Sprite();
        sq.graphics.beginFill(0x0000FF);
        sq.graphics.drawRect(10, 10, 100, 100);
        sq.graphics.endFill();
        super.addChild(sq);

        //Call Tracer Function
        tracer();
        }
    }
}
  • 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-17T06:46:35+00:00Added an answer on May 17, 2026 at 6:46 am
    public class MainClass extends Sprite
    {
        private var subClass:SubClass;
    
        public function MainClass
        {
           var controller:Controller = new Controller();
    
           subClass = new SubClass(controller);
           addChild( subClass );
        }
    
        private function init():void
        {
           subClass.doWhatever();
        }
    }
    
    public class Controller
    {
    
        public function doThis():void
        {
         }
        public function doThat():void
        {
             trace("controller do that...");
         }
        public function doSomethingElse():void
        {
         }
    }
    
    public class Subclass extends Sprite
    {
         private var controller:Controller;
    
         public function Subclass(controller:Controller)
         {
             this.controller = controller;
             trace( "new Subclass instance!" );
         }
    
         public function doWhatever():void
         {
             controller.doThat();
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has there been any attempt and creating a formalized method for organizing CSS code?
I am using the following code to attempt to read a large file (280Mb)
If I attempt to connect to Mac OS X 10.5 Leopard's built in vnc
In an attempt to add some parameter validation and correct usage semantics to our
When you attempt to declare an unsigned variable in C#.NET with a value outside
I've decided to attempt using the double submitted cookies technique to attempt to prevent
This is an attempt to rephrase a question I asked earlier. I'd like to
When I attempt to use the iterator form of parsing for a Spirit grammar
For some reason when I attempt to make a request to an Ajax.net web
This is a pretty straight forward attempt. I haven't been using python for too

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.