Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global variables

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
0
0
GB
Another quicky - I'm used to coding where I can declare global variables at the start of a project and any funciton can get/set them. For flash now I'm breaking things into functions, I'm finding myself repeatedly passing things lik ean xml root node to another function. And if a function loads in a bunch of text as part of the function, how will other functions it goes back to ahve access to them? I'm not sure which is the best way to do it in AS o.o

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
If you're using them in a class, you can make them class-level variables.

Code:
public class MyClass
{
    public var MyVar:Object = new Object();

    // Your functions, constructors, etc.
}

Of course, you should use Properties, rather than public variables.

Code:
public class MyClass
{
    private var _myVar():Object = new Object();

    public function get MyVar:Object
    { return _myVar; }

    public function set MyVar(value:Object):void
    { _myVar = value;

    // Your functions, constructors, etc.
}

-------------------------
Matt Grande
C# Master.
Ruby on Rails Admirer.
ActionScript Student.
JavaScript Hate-Monger.
 
I'm writing in flash 6 mx AS 2 and not as a class ^__^;

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 

After a quick read there I think I've got it sussed. I'm just using _global.varname to make my variables now and it's replaced the need to keep pasing variables around between all the functions, huzzah :)

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Having done this, I've got another quickie I don't want to waste a new topic on :p

That being that when I look at the variables that contain text like "characters you'd escape" apostrophies etc, they come out in the textbox as html entities, eg &pos; and I've tried things I can think of lik eunescape() but I dunno AS well enough to know what function to convert them back. What is it? x.x I tried saying .htmltext on the textbox instead of just .text but that didn't help either.

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top