ActionScript 3.0 :: Singleton Pattern Classes As Parameters?
Aug 7, 2011package public class Singleton private static var _instance:Singleton=null;
[Code]...
package public class Singleton private static var _instance:Singleton=null;
[Code]...
I can't understand why should I even use the Singleton pattern in ActionScript 3. Can anyone explain me this? Maybe I just don't understand the purpose of it. I mean how it differs from other patterns? How it works? I checked the PureMVC source and it's full of Singletons. Why are they using them in the View, Module, Controller?
View 2 Repliesa little foggy on passing variables to the Constructor from a Singleton instance. Could someone enlighten?
From timeline:
Code:
var c:Calculator = Calculator.getInstance(5,20,30);
[Code]...
I'm trying to call AMFPHP two times on a single ActionScript method and what happen is that only the first call succeed. The second one doesn't return an error, doesn't alertsanything, it is more likely that it doesn't even happens and I'm not sure why.Here is an example:
public function editSomething():void{
if(dgChild.selectedIndex == -1){
Alert.show("You need to select a register in order to edit it.");
[code].....
I am not able to understand, why a static class cannot replace a Singleton design pattern .
Cannot a static class, can be used to ensure, the class is never/once only, instantiated. Because that is the facility "static" key words provide , however it doesnot allow instantiation, but that is much similar to the limitation of instantiation once only.
is there a simple way to pass a parameter in the "new" statement for a class that has been defined in the IDE? Like so:var newInternalClass:InternalClass = new InternalClass (someVar);So that when the new class is instantiated it has someVar to work with?
View 3 RepliesI declare this class which has a value x (In it's own document)[code]...
View 3 Repliesi'm trying to search a string for a particular pattern, and replace it with elements from within the pattern... for example..here's the given string...if you want to learn how to use regexp, {url===http://somesite.com, text===click here}.
the pattern...
{url===http://somesite.com, text===replacement text}
and the intended result...
if you want to learn how to use regexp, click here.
of course, i'll extract the url and do something else with it... i'm just wondering what the regexp is for that pattern, and how i can extract things from the results returned.
I am looking at the singleton design pattern and trying to really understand what is going on here. But I have some questions that it would seem my logic and/or the way I am reading this is wrong. Take the following code for example
[Code]...
In the Singleton design pattern you can throw a runtime error if the instance has already been created. But this doesn't work when your singleton class extends another class and has to call super() in its constructor, because (for some reason) you cannot call super() if you've already called throw(), or in fact, you cannot compile code that has a potential call to throw() (for example, in an IF statement) that comes BEFORE that call to super().
View 4 RepliesWhat is the possibility of a singleton reference to be lost. Well I created a swf singletonpara a store containing some sound features of the software that I created and it's one time or another error saying that the reference is null
View 5 RepliesI have a doubt,.... How would you create a Singleton class in Flex...
Is there any convention like the class name should eb Singleton or it should extend any other class.
How many Singleton class can a project have?
Can anyone say the real time usage of a Singleton class?
I am planning to keep my components label texts in a Singleton class... Is it a good approach.
I have a few classes in my project which aren't display objects, but they need to know about the stage of my project (stage.stageWidth, stage.stageHeight). Is there a simple way to pass this information along to my classes without using a Singleton or passing these items in as parameters into the constructor??
View 3 RepliesIf multiple instances of a singleton are trying to update the same property simultaneously, will there be any conflicts? How does AS3 handle the order?Flash is currently single-threaded.. will the write order be an issue when it becomes multi-threaded?
View 3 RepliesThe use I have for it is for storing user credentials, and calling a transfer object that functions as a sort of "cache" for the current session in all of the flex modules.
Thinking about objects that have to be present in every module. Is there any alternative to a singleton instance for this?
I'm storing my model data in a Singleton called ModelLocator. This is pretty common...
Can I look at this data in the debugger?
[Edited - Title changed]
How can I define my own global function which will be accessible throughout the whole package or better, program? Alternatively, how can I define a singleton object? Should I use static?
View 3 RepliesI'm trying to do singleton movieclip from library, but can't get it work, how should I proceed?[code]1136: Incorrect number of arguments.Expected 1.And it is refering to the MyMovieClip.as file, to the line where I have "_myMovie = new MyMovie();".
View 6 RepliesI'm trying to load swf from 127.0.0.1 into my main.swf with Flash Pro
Both swfs have Singlenton class
How to make it that loaded swf use Singlenton of main.swf ?
I did
ActionScript Code:
var lc:LoaderContext = new LoaderContext();
lc.applicationDomain = ApplicationDomain.currentDomain;
myLoader.load( new URLRequest("http/127.0.0.1/loaded.swf"),lc);
anyway I have 2 different Singlenton classes one comes with loaded.swf another in main.swf and variables not shared
is any way I can merge this values?
I am trying to create a singleton class, that extends Sprite. It seems to work correctly, but it doesn't actually update the screen.If I access my instance and change the properties (x,y,alpha,etc) they will all update, but the display doesn't change.eg:My clip starts at x=0.MyClass.getInstance().x = 99;trace(MyClass.getInstance.x); //traces 99, but it still appears at 0 on the screen.
View 7 RepliesSo I have this class "G" that I use for global vars, and that kind stuff.
Now I want to dispatch an event from that class and no matter what I do the compiler throws the same error: "Call to a possibly undefined method dispatchEvent."
I have already tried extending the EventDispatcher class...
Code:
package {
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
[Code]....
I know singleton class is not supporting in Flex.Because it does not access private constructor. But i want to make a class is singleton class.
View 2 RepliesI know actionscript does not allowed private contstructor at any time and But if i want to write a sinlgleton class in action script So how to implement it in actionscript.
Can anyone provide an sample example of a singleton pattern in actionscript?
I know actionscript does not allowed private contstructor at any time and But if i want to write a sinlgleton class in action script So how to implement it in actionscript.
Can anyone provide an sample example of a singleton pattern in actionscript?
I have created a Network class singleton to represent our xml calls. The purpose of the class is to load in various xml calls and then load into a 2 dimensional array.The 2 main variables that I want to release are "mChannels" and "epgXML". When I call the function term(), the memory never gets released. I am initializing this Network class once (mNetwork = Network.init(), and then referencing the singleton through the getInstance function. I call the term() function but the memory never goes down. What am I doing wrong with garbage collection?[code]
View 1 RepliesWHY would I use this pattern to hold variables accessible to other swfs throughout the project when I can just keep them in the container movie and access them as desired.Is there any advantage like optimization, security, ease of use etc..how I access a varibale in a parent mc unless answered here too as it is in the same category.Is it best to access a varibale in the parent using
1. MovieClip(parent.parent).variableTargeted OR import com.parentAsDocument; And then access the variable
I am developing an AS3 application which uses a Singleton class to store Metrics in Arrays. It's a Singleton because I only ever want one instance of this class to be created and it needs to be created from any part of the app. The difficulty comes when I want to unit test this class. I thought adding public getters and setters would enable me to unit test this properly and would be useful for my app. I have read that changing to a Factory pattern will enable unit testing or using Inversion of control. This would of course make it more flexible too. I would like to know of people's thoughts on this matter as there are SO many conflicting opinions on this!
View 1 RepliesI have a ManagerClass with a Singleton implementation inside, I get the instance by calling ManagerClass.getInstance().
Can I get that same instance by just having the class name as a string? I have tried something like:
var theInstance:* = getDefinitionByName("ManagerClass").getInstance as Class;
theInstance.doTrace(); // I get a 1009 error here
I WIh know how Can I use a singleton class to make only a one instance of a movieclip on the stage.I use this code to make my movieclip instance:
Code:
var mioOggetto:wwp = new wwp();
mioOggetto.y = stage.stageWidth /2 -200;[code].....
My first swf loads a singleton class and instantiate it , and I access to it in the following swf's files (they were loaded in local system).
Now I have to load all swf via http. The issue is when I load second movie throw the first one, I can't get the singleton instance... it seems it lost reference...