Following is code for singleton implementation in MXML Component [SingletonComponent].
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" width="100%" height="100%" creationComplete="init()"> <fx:Script> <![CDATA[ private static var _container:SingletonComponent; private static var _lock:Boolean = false; private function init():void { _container = this; _lock = true; //make sure only one container is created. } public static function getInstance():SingletonComponent { if (!_lock) { _container = new SingletonComponent(); _lock = true; } return _container; } ]]> </fx:Script> </s:Group> On Wed, Jun 22, 2011 at 12:07 PM, Utkarsh Chachad <[email protected]>wrote: > Sorry Satish ... got the name wrong :) > Utkarsh. > > > > On Wed, Jun 22, 2011 at 12:06 PM, Utkarsh Chachad <[email protected]>wrote: > >> Hi Santosh, >> >> Ur singleton is completely messed up. >> Firstly the constructor is public with no parameters which means I can >> create an object of XYZ directly. Secondly in the getInstance method u are >> returning an object of GybModel and not XYZ which is not what u want. >> >> Honest mistake i hope ... >> >> Here is the proper code >> >> package >> { >> public class XYZ >> { >> private static var _instance : XYZ ; >> public function XYZ (gybm:GybModel) >> >> { >> } >> >> public static function getInstance(): XYZ >> { >> if(_instance == null) >> { >> _instance = new XYZ( new GybModel() ) ; >> } >> return _instance; >> } >> } >> >> class GybModel >> { >> public function GybModel() >> {} >> } >> >> Utkarsh. >> >> >> >> On Tue, Jun 21, 2011 at 6:11 PM, Satish Pawar <[email protected]>wrote: >> >>> Just create class with static var and one static function to check for >>> the class instance >>> Example: >>> >>> public class XYZ { >>> private static var _instance : XYZ ; >>> public function XYZ () >>> { >>> } >>> >>> public static function getInstance(): XYZ >>> { >>> if(_instance == null) >>> { >>> _instance = new GybModel(); >>> } >>> return _instance >>> } >>> } >>> >>> On 21/06/2011, Akshar Kaul <[email protected]> wrote: >>> > do you mean you want to implement singleton pattern ? >>> > >>> > ---> Akshar Kaul <--- >>> > >>> > >>> > >>> > On Tue, Jun 21, 2011 at 17:45, Flex based developments < >>> > [email protected]> wrote: >>> > >>> >> Hello, >>> >> >>> >> I want to create single instance of MXML,please do let me know if it >>> >> is possible. >>> >> >>> >> Thanks. >>> >> >>> >> Sincerely, >>> >> >>> >> Abhilash >>> >> >>> >> -- >>> >> You received this message because you are subscribed to the Google >>> Groups >>> >> "Flex India Community" group. >>> >> To post to this group, send email to [email protected]. >>> >> To unsubscribe from this group, send email to >>> >> [email protected]. >>> >> For more options, visit this group at >>> >> http://groups.google.com/group/flex_india?hl=en. >>> >> >>> >> >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> Groups >>> > "Flex India Community" group. >>> > To post to this group, send email to [email protected]. >>> > To unsubscribe from this group, send email to >>> > [email protected]. >>> > For more options, visit this group at >>> > http://groups.google.com/group/flex_india?hl=en. >>> > >>> > >>> >>> >>> -- >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> ------------------------------ >>> *Thanks&Regards* >>> * >>> Satish Pawar >>> IBM-Flex Developer* >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Flex India Community" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/flex_india?hl=en. >>> >>> >> > -- > You received this message because you are subscribed to the Google Groups > "Flex India Community" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/flex_india?hl=en. > -- <[email protected]> -- You received this message because you are subscribed to the Google Groups "Flex India Community" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.

