[Flashcoders] MovieClipLoader/loadMovie vs. digit on instance name

2006-12-09 Thread Wagner Amaral

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() * 100 ));
var _newWin:Window = Window( _tgt.attachMovie(_linkage, newWin_ +
randName, _tgt.getNextHighestDepth(), initObj) );

which gives me something like: _level0.windowContainer.newWin_123456

however, when I tried to load an external image into a movieclip
inside this new Window, MovieClipLoader.loadClip() failed silently,
and loadMovie() gives an error in the path (doesn't specify which
path, but then I found it was the destination movie's path)
setting properties like _newWin.textContainer.text = 'xyz'; works ok,
but I could not load an image into _newWin.imageContainer, even though
I can trace it (gives me
_level0.windowContainer.newWin_123456.imageContainer)

then I did this, and the image loaded correctly, along with the text properties:

var randName:String = String(Math.round( Math.random() * 100 ));
var randNameArray:Array = randName.split( '' );
var newNameArray:Array = new Array( randNameArray.length );
for ( var i:Number = 0; i  randNameArray.length; ++i ) {
newNameArray[i] = String.fromCharCode( 97 + Number(randNameArray[i]) );
}
randName = newNameArray.join( '' );
var _newWin:Window = Window( _tgt.attachMovie(_linkage, newWin_ +
randName, _tgt.getNextHighestDepth(), initObj) );

basically I converted the numbers into their letter equivalent,
starting from a, which gives me something like:
_level0.windowContainer.newWin_abcdef

and now both loadMovie() and MovieClipLoader.loadClip() loads the
image correctly

my question is, why is this happening? isn't a digit a valid
'variable-letter' in flash ?
is this a known issue, or is it just me? am I doing something wrong?
___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] MovieClipLoader/loadMovie vs. digit on instance name

2006-12-09 Thread Alain Rousseau

Hi Wagner,

INMHO, the best way to add your numbers to the name of MovieClip is to 
first define a variable as the base name of your mc, then add the number 
(id) to that base name. I do it like this :


var baseName:String = newWin_;
var mcID:Number = Math.round( Math.random() * 100 );
var mcName:String = baseName + mcID;

you'll be sure to allways have a string that way!

I usually use this in a loop (for or while) where I use an incremental 
number (i++)


var baseName:String = newWin_;
for (var i:Number = 0; i  maxMC; i++) {
   var mcName:String = baseName + i;
}

HTH

Alain

Wagner Amaral 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() * 100 ));
var _newWin:Window = Window( _tgt.attachMovie(_linkage, newWin_ +
randName, _tgt.getNextHighestDepth(), initObj) );

which gives me something like: _level0.windowContainer.newWin_123456

however, when I tried to load an external image into a movieclip
inside this new Window, MovieClipLoader.loadClip() failed silently,
and loadMovie() gives an error in the path (doesn't specify which
path, but then I found it was the destination movie's path)
setting properties like _newWin.textContainer.text = 'xyz'; works ok,
but I could not load an image into _newWin.imageContainer, even though
I can trace it (gives me
_level0.windowContainer.newWin_123456.imageContainer)

then I did this, and the image loaded correctly, along with the text 
properties:


var randName:String = String(Math.round( Math.random() * 100 ));
var randNameArray:Array = randName.split( '' );
var newNameArray:Array = new Array( randNameArray.length );
for ( var i:Number = 0; i  randNameArray.length; ++i ) {
newNameArray[i] = String.fromCharCode( 97 + 
Number(randNameArray[i]) );

}
randName = newNameArray.join( '' );
var _newWin:Window = Window( _tgt.attachMovie(_linkage, newWin_ +
randName, _tgt.getNextHighestDepth(), initObj) );

basically I converted the numbers into their letter equivalent,
starting from a, which gives me something like:
_level0.windowContainer.newWin_abcdef

and now both loadMovie() and MovieClipLoader.loadClip() loads the
image correctly

my question is, why is this happening? isn't a digit a valid
'variable-letter' in flash ?
is this a known issue, or is it just me? am I doing something wrong?
___
Flashcoders@chattyfig.figleaf.com
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




___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] MovieClipLoader/loadMovie vs. digit on instance name

2006-12-09 Thread T. Michael Keesey

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() * 100 ));
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/
___
Flashcoders@chattyfig.figleaf.com
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