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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:21:45+00:00 2026-06-04T21:21:45+00:00

I created this simple example because I was using a more complex class, a

  • 0

I created this simple example
because I was using a more complex class, a menu item that I wanted to initialise all the settings in the Main class and then add it in in the Game class (and updating it) when needed (both classes are separate)

Class: Main (document class, is (ideally) where everything is initialised/created)

    public class Main extends MovieClip
    {
            //testing passing on reference to Game
        private var testBitmap:Bitmap;
        private var testBitmapData:BitmapData;
        private var testArray:Array;

            public function Main():void
            {
                testBitmapData = new BitmapData(256, 256, false, 0xCCDDEE);         
                testBitmap = new Bitmap(testBitmapData);            
                testArray = [];
                testArray.push(testBitmap);    //Array for reference

                game = new Game(540, 960, testArray); 
                    //create Game class, pass reference to Object
                game.x = 0;
                game.y = 0;
            }
     }

Class: Game (created by document class, is (ideally) where everything runs)

    public class Game extends MovieClip
    {

            private var testingArray:Array

            public function Game(gameWidth:int, gameHeight:int, testArray:Array):void
            {
                    this.testingArray = testArray;  //assign to local Array and access
                    addChild(testingArray[0]);  
             //addChild to Game from an item intialised in Main, doesn't work >___<
            }
    }

.

.

.

the thing is, in my original Game class; it receives an initial bundle of cached BitmapData and a list Array that tells it which BitmapData it needs to cycle through
cut-down here (and that reference only for updating works (if I addedChild in Main already):

    public function Game(gameWidth:int, gameHeight:int, cachedBitmapClipArray:Array)
    {

            this.cachedBitmapClipArray = cachedBitmapClipArray;


            private function update():void
            {           
                for each (tempCachedBitmapClip in cachedBitmapClipArray)  
                {
                    tempCachedBitmapClip.updateCurrentTile();   
          //but updating through the reference to an item initialised in Main works !!
                }
            }

    }

.

how do I make the reference and passed in objects (or have access to) behave as in the original instance ?? (being able to addChild)

i.e. can objects cross ‘scopes’ (??) or should objects only be controlled (instantiated) in the class where they have been initialised

  • 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-04T21:21:46+00:00Added an answer on June 4, 2026 at 9:21 pm

    Well to answer the last question, yes objects can be passed from one object to another. I’m having a hard time understanding what exactly the problem is though. In generic programming terms Object or any other complex type are passed by reference, primitive types are also passed by reference but the internals of the AVM handle them in such a way as to treat them as passed by value. For a pretty clear (in my eyes at least) explanation of how arguments are passed via function/method calls, read here:
    http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f56.html

    Check out other areas in the tree navigation on the left for more details on the language itself.

    One thing to note though I think the compiler will work around this error, in the first bit of code you posted Game has a return value of :void for a constructor there should be no declared return type since it should be implicitly typed as whatever the class is.

    To add some explanation in my own words regarding pass by reference or pass by value. Pass by value means that the value of the object, that is the bytes stored at the location pointed to by the variable are actually copied to a new memory location which is then used. What this means in practice is they are not the same bytes of memory but rather they are two separate memory locations each with the same value stored in them, modification of one value after the passing doesn’t affect the original. Pass by reference is to say you pass the memory location therefore no new memory for the value is allocated, both values are actually pointing to the same memory location (the pointer to them itself may be different but that pointers both point to the same location in memory). In this case the objects are the same.

    What you’re doing is advisable, dividing the labor and enapsulating particular types of functionality in classes does make the code easier to work with. I think the only problem would be if the Game object itself is never added as a child to something in the display tree (something that is attached to the stage). It appears you’re creating a new Game and setting it’s position but never adding it as a child to the stage, then adding anything to Game is never a part of the display tree.

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

Sidebar

Related Questions

I created a simple application inspired by this example in order to test all
I've created this simple example program, but this doesn't work. it won't connect. any
in this example from opencv, why didn't we create a simple variable img (instead
I'm trying to create a basic version of this example in CoffeeScript: http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/ .
I've created this simple GUI: from tkinter import * root = Tk() def grabText(event):
Hi1 I just created a DLL with GCC. It only contains this simple function:
I created a simple netbeans plugin (see this tutorial ) and now i wanna
I created a simple speech recognition service: for this purpose I created a subclass
I created a simple Rating user control, the problem this control won't in WinRT
This may be a simple answer, but I'm trying to add a dom-created element

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.