Written by Philip
The Singleton class, coded in AS3, is designed to restrict instantiation of a class to only one object. It's good when you only want one object across the whole of your application. An example could be you load in a load of xml data and you want to store the values of the xml for use throughout the application. In AS3 we can write a Singleton Class in the following way. We use the getInstance() to return the object created.
1 |
package com.howtocode |
To access a variable from the Singleton class we use the following.
1 |
import com.howtocode.Singleton; |
You can of course do something really cool which is place something like place
1 |
<mx:Button id="flexButton" label="{model.flexData}">
|
into you're MXML and when flexData is changed in your Singleton Class it automatically updates you're MXML as we've set the whole Singleton Class as [bindable].
Written by Philip
1 |
switch(condition) |