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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:05:15+00:00 2026-06-11T21:05:15+00:00

I am trying to pass a variable budget from my DocumentClass of a flash

  • 0

I am trying to pass a variable “budget” from my DocumentClass of a flash file, to a class.

Currently I have :

(DocumentClassv5 , this is the code thats attached to the flash file in the properties panel, some code ommited)

package  
{

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.*;
import flash.ui.Keyboard;
import flash.display.Stage;
import flash.text.TextFieldType;
import flash.media.Sound;
import flash.media.SoundChannel;    
import miniGameOne;
import floorTileMC;


import flash.display.Loader;
import flash.net.URLRequest;



public class DocumentClassv5 extends MovieClip 
{
    /*#################################
    ## Defining Variables            ##
    #################################*/

    public var budget:int = 0;

    var gameOne:miniGameOne = new miniGameOne();
        /*#################################
    ## Constructor                   ##
    #################################*/     
    public function DocumentClassv5() 
    {
        /*#################################
        ## Adding Event Listeners        ##
        #################################*/


        trace("Document class loaded");
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /*###################################################
    ## Begins the mini game                            ##
    ###################################################*/           
    public function begin(evt: MouseEvent)
    {
        beginGame.visible = false;
        beginGame.removeEventListener(MouseEvent.CLICK, begin);
        budget = 500;

        cleanListeners();
        gameOne.loadGame();
        trace(gameOne.testVar);
        trace(floorTile.testVar2);

        /*#################################
        ## Adding Event Listeners        ##
        #################################*/         


        trace("Game started");
    }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
}

Then I have the miniGameOne class file, which at the moment does nothing

I also have another class file, called tileFloorMC. This is attached to a symbol.

package  
{

import flash.display.MovieClip;
import flash.events.MouseEvent;
import DocumentClassv5;


public class floorTileMC extends MovieClip 
{
    var propertyA:Number;
    //var hackerClass:DocumentClassv5 = new DocumentClassv5;
            public var testVar2:int = 50;

    public function floorTileMC() 
    {
        this.propertyA = randomRange(100, 500);

        this.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
        this.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);
    }
    private function manageMouseOver(evt: MouseEvent)
    {
        this.gotoAndStop(2);
        //trace(mainClass.budget);
    }
    private function manageMouseOut(evt: MouseEvent)
    {
        this.gotoAndStop(1);
        //mainClass.budget += 1;
    }
    private function randomRange(minNum:Number, maxNum:Number):Number   
    {  
        return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);  
    }       

}

}

Now, essentially I will need to be able to pass budget from DocumentClassv5 TO floorTileMC, and then BACK to DocumentClassv5. At the moment, I can pass anything from floorTileMC and anything from miniGameOne into DocumentClassv5, but when i try and pass from floorTileMC to DocumentClassv5, I get error
Error #2136: The SWF file file:///yadayada/GameV5.swf contains invalid data.

More specifically, as soon as I uncomment //var hackerClass:DocumentClassv5 = new DocumentClassv5;

Any help would be greatly appreciated!

Thanks,

Tiffany

  • 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-11T21:05:16+00:00Added an answer on June 11, 2026 at 9:05 pm

    You’re trying to instantiate your document class in a subclass:

    var hackerClass:DocumentClassv5 = new DocumentClassv5();
    

    You want access to access the existing instance, not create a new one.

    One thing you can do, is create a static reference to your document class. (see code sample below)

    Static references can get ugly though, and you may just want to pass a reference of your doc class to your other classes when you instantiate them.

    Both method below:

    In your document class:

    //instead of the line below:
    var gameOne:miniGameOne = new miniGameOne(); //It's a bad idea to instantiate non primitive objects before the constructor of your document class runs.
    
    //just declare it, and instantiate it in the constructor
    var gameOne:miniGameOne;
    
    //if you want to use a static reference:
    public static var me:DocumentClassv5;
    
    public function DocumentClassv5() 
    {
        /*#################################
        ## Adding Event Listeners        ##
        #################################*/
    
        //if using the static var me, set it's value to this (the instance of the document class):
        me = this;
    
    
        trace("Document class loaded");
        gameOne = new miniGameOne(this); //pass a reference to the document class if NOT using the static var me
    
    
    }
    

    If using the static var me, you access it by doing the following from any class:

    DocumentClassV5.me.budget;
    

    Another cleaner alternative (if the values you need access to aren’t really directly tied to any class, eg. global preferences), is make a whole new class that is just static (doesn’t get instantiated) to hold your preferences.

    package {
        public class Global {
    
            public static var budget:Number = 50;
    
        }
    }
    

    Then you’d access budget by importing your Global class and doing Global.budget = 5

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

Sidebar

Related Questions

I'm trying to pass variable from PHP file to Perl file by this code
I'm trying to pass a variable from one include file to another. This is
I am trying to pass a variable from a function to a class. Example
New to MVC, trying to pass a variable from Flash using FSCommand (works well
I am trying to pass a variable to a included file. I have done
I am trying to pass a variable from a.js file to b.js file. a.js
I'm trying to pass a variable through a ssh connection, like this: working_dir=/home/user/some_dir/ ssh
I'm trying to pass a variable from a child form that contains a DataGridView,
I am trying to pass a variable within a header link. I have tried
i am trying to pass in a selector into the ID variable but this

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.