On 12/9/06, Wagner Amaral <[EMAIL PROTECTED]> wrote:
Yesterday I was building a WindowManager class, and I wanted to assign
random names to each created window. So I went for the obvious:
var randName:String = String(Math.round( Math.random() * 1000000 ));
var _newWin:Window = Window( _tgt.attachMovie(_linkage, "newWin_" +
randName, _tgt.getNextHighestDepth(), initObj) );
which gives me something like: _level0.windowContainer.newWin_123456
A bit of a tangent, but this doesn't seem like a good strategy to me.
Although the odds are against it (literally a million to one), it is
possible to have a duplicate name (especially since "random" numbers
are not really random). If the goal is to have a unique name for each
instance, why not just keep a static integer variable and increment it
each time?
public static var LINKAGE_ID:String = "Window";
private static var windowNameIndex:Number = 0;
public static function createWindow(parent:MovieClip, init:Object):Window {
var windowName:String = "window" + String(windowNameIndex++);
var clip:MovieClip = parent.attachMovie(LINKAGE_ID, windowName,
parent.getNextHighestDepth(), init);
return Window(clip);
}
Or am I missing some requirement?
--
T. Michael Keesey
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com