Global variables

In the Fleb Framework, a very simple but efficient singleton class for handling global variables is used: VarCentral. You can easily use it for your own purpose, add any value (string, object, array… whatever) and access it from anywhere in your project.

Initializing VarCentral

In order to use VarCentral, you must first initialize it (in whichever class you want to use it, for example, MyPage.as). To do so use the code below.

// import the class
import net.kaegi.utils.VarCentral
...
// shortcut
private var varcentral:Object = VarCentral.getInstance().vars;

Use the reserved global variable names

You should not overwrite the following global variables used by the Fleb Framework itself. But it is easy to avoid it, they all start with "fleb". Here is a list of fleb global variables you may need to use.

varcentral.flebStructureXML

Stores the structure.xml. For example:

trace(varcentral.flebStructureXML.navigation) // traces 'navigation' node

varcentral.flebNavigationManager

Stores a reference to the global navigation manager class.

varcentral.flebLanguage

Stores the language ID (0, 1, 2, etc.) of the currently active content page (defined in structure.xml). For example:

trace(varcentral.flebLanguage) // traces '1'

varcentral.flebStage

Stores a reference to the stage object. For example:

trace(varcentral.flebStage.stageWidth) // traces '1024'
trace(varcentral.flebStage.stageHeight) // traces '768'

varcentral.flebActiveData

Stores the data object of the currently active content page (defined in structure.xml):

  • data.swfArr
  • data.sourceArr
  • data.titleArr
  • data.addressArr

The arrays (swfArr etc.) contain 5 values for 5 languages. For example, if varcentral.flebLanguage is 2, then the third element of the arrays will be used.

trace(varcentral.flebActiveData.addressArr[0]) // traces '/en/products/'

varcentral.flebActiveID

Stores the button ID of the currently active content page (defined in structure.xml). For example:

trace(varcentral.flebActiveID) // traces 'contact'

varcentral.flebActiveBtn

Stores a reference to the currently active NavigationButton2.

trace(varcentral.flebActiveBtn.id) // traces 'my_btn_id'

varcentral.flebActivePage

Stores a reference to the currently active content page.

varcentral.flebPreviousBtn

Stores a reference to the NavigationButton2 that was active before the current button.

Warning!

The flebPreviousBtn, flebPreviousID and flebPreviousData variables are set ONLY if you press a navigation button for the first time. Until then they are null. For example, when you enter the site for the first time (by browser address), these three variables are null!

Create your own custom global variables

You can create your own global variables, for example:

// import the class
import net.kaegi.utils.VarCentral
// shortcut
var varcentral:Object = VarCentral.getInstance().vars
// add some values
varcentral.foo = "bar";
varcentral.foo2 = "test";
varcentral.blabla = "gugus";

Now you can use these values from anywhere in your project (e.g. another SWF):

// import the class
import net.kaegi.utils.VarCentral
// shortcut
var varcentral:Object = VarCentral.getInstance().vars
// use values
trace(varcentral.foo) // returns: "bar"
trace(varcentral.foo2) // returns: "test"
trace(varcentral.blabla) // returns: "gugus"

To find out what variables contain the varCentral object, just use the code below:

for(var prop in varcentral) {
    trace( prop+" is "+varcentral[prop] );
} 

A good practice is every time you create your own global variable, add it in the upper comment section in VarCentral.as, so that you can easily keep track of them.

See this post.

Post A Comment

Anti-Spam Quiz: