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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:18:32+00:00 2026-05-14T18:18:32+00:00

i’m confused with the term global in AS3. within my main controller class, i’ve

  • 0

i’m confused with the term “global” in AS3. within my main controller class, i’ve defined a variable (myNum) which i would like to access throughout all class .as files within the same package.

//Controller class

package myApp
{
public var myNum:int = 24; //try to access myNum in mySprite class

public class Main extends Sprite
    {
    }
}

______________________________

//Object class

package myApp
{
public class mySprite extends Sprite
    {
    trace (myNum);
    }
}

the above code returns the following error:

5006: An ActionScript file can not have more than one externally visible definition

what is the proper way to set up a list of global variables that can be accessed throughout the entire scope of a package?

  • 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-14T18:18:32+00:00Added an answer on May 14, 2026 at 6:18 pm

    Static variables could accomplish this.

    You can declare a variable as internal static so that other classes in the same package can use it. Or you can declare it as public static so that all classes in your project can use it, even if they’re in a different package.

    In the code below, myNum1 is accessible by classes in the same package, whereas myNum2 can be accessed from anywhere.

    package myApp
    {
        public class Main extends Sprite
        {
            internal static var myNum1:int = 1;
            public static var myNum2:int = 2;
        }
    }
    

    Example of access from the same package:

    package myApp
    {
        public class ClassInSamePackage
        {
            public function doSomething():void
            {
                trace(Main.myNum1); // traces 1
                trace(Main.myNum2); // traces 2
            }
        }
    }
    

    Example of access from a different package:

    package otherApp
    {
        import myApp;
    
        public class ClassInDifferentPackage
        {
            public function doSomething():void
            {
                trace(Main.myNum1); // error!
                trace(Main.myNum2); // traces 2
            }
        }
    }
    

    Internal is actually the default access modifier in AS3, so writing internal static var
    is the same as writing static var. But it is probably better to write internal static var anyway just to be clear.

    PS It’s unclear from your example whether you’ve placed the two classes in one or two files. If you’ve placed them both in only one file, bear in mind that one AS file can only contain one class.

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

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a

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.