all groups > flash (macromedia) > september 2006 >
You're in the

flash (macromedia)

group:

bad programmin practice question


bad programmin practice question calmchess333
9/30/2006 2:51:07 PM
flash (macromedia):
In the following script is using cont_mc.loadmc for 4 diffrent variables a bad
proggraming practice?
I'm asking because i've read that the best programming practice is to use
a unique name for every variable so that script and flash conflict issues
don't arise.......if you consider this a bad programming practice ...please
show me the way you would write the below code.



_root.createEmptyMovieClip("cont_mc", 1);
cont_mc.loadmc = loadMovie("xxx.swf");
cont_mc.loadmc._x = 100; // this won't work
cont_mc._x = 100; // but this will
cont_mc._y = 200;
Re: bad programming practice question coldMiner
9/30/2006 9:16:33 PM
correct code:
_root.createEmptyMovieClip("cont_mc", 1);
_root.cont_mc.createEmptyMovieClip("loadmc", 1);
cont_mc.loadmc.loadMovie("xxx.swf");
cont_mc.loadmc._x = 100;
cont_mc._x = 100;
cont_mc._y = 200;

Here is another way of doing it, how you code depends on the level of control
you want,
and the size and how complex the project is.

var cont_mc:MovieClip = this.createEmptyMovieClip("cont_mc",
this.getNextHighestDepth());
var loadmc:MovieClip = cont_mc.createEmptyMovieClip("loadmc",
cont_mc.getNextHighestDepth());
cont_mc._x = 100;
cont_mc._y = 200;
loadPic(loadmc, 25, 100);
// load swf:
function loadPic(who:MovieClip, xx:Number, yy:Number) {
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc._x = xx;
target_mc._y = yy;
};
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(mclListener);
mcl.loadClip("xxx.swf", who);
}
AddThis Social Bookmark Button