Written by Philip
The Singleton class, which can be used in Flex / Flash, which are of course coded in AS3, is designed to restrict instantiation of a class to only one object. It's great 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 Flex / Flash we can write a Singleton Class like the following. 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].