all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

Function question


Re: Function question David Stiller
9/7/2005 3:24:22 PM
flash actionscript:
gijbelsy,

[quoted text, click to view]

Things often "work" or "don't work" in ActionScript depending on how you
path to your objects. The MovieClip class describes all the methods and
properties of any movie clip instance (an instance of a movie clip on the
Stage). The MovieClip.removeMovieClip() method only "works" when it is
applied to a movie clip instance, such as whatever pBar is. If pBar is a
movie clip, then pBar.removeMovieClip() means, "Hey,
instance-of-a-movie-clip, who goes by the instance name pBar ... look into
your bags of tricks, since you're a MovieClip instance, and call your
removeMovieClip() method." And in this context, pBar must be a movie clip
instance whose parent is "this", which may be another movie clip or a
timeline. If "this" (whose meaning changes on context) doesn't refer to a
movie clip or timeline, then pBar may not be a movie clip instance, and
duplicateMovieClip() won't have any meaning.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Function question gijbelsy
9/7/2005 6:51:37 PM
Why is this line working outside a function:
this.pBar.removeMovieClip();
and when I put it in a function, it suddenly doesn't work anymore.

Code is listed below.

//**********************************************************
//Functgion to write the images to the stage with preloader
//**********************************************************
function WriteImages(strLocation:String, bteNumber:Number) {
//Call the function to write the images to the stage
//******************************
//SET-UP
//******************************
var xPBar:Number = 0;
var yPBar:Number = 45;
var xMovie:Number = 0;
var yMovie:Number = 0;
var xCount:Number = 4;
var minScale:Number = 12;
var maxScale:Number = 25;
//***************************************
//Init for loop to loop trough all images
for (i=0; i<=bteNumber; i++) {
//Attach the preloader movie.
var pBar = this.attachMovie("ProgressBar", "ProgressBar"+i,
this.getNextHighestDepth());
//Position the preloader movie (centered)
if ((i%4) == 0) {
if (i>=4) {
yMovie = yMovie+100;
yPBar = yPBar+100;
}
}
pBar._x = (143*(i%4))+60;
pBar._y = yPBar;
//Set the progressbar to 0
with (pBar.bar_mc) {
_xscale = 0;
}
//Create listner object for preloader
var mclListener:Object = {pBar:pBar};
//Actions to do when loading starts
mclListener.onLoadStart = function(target_mc:MovieClip) {
this.pBar.bar_mc._xscale = 0;
};
//Actions to do while loading is in progress
mclListener.onLoadProgress = function(target_mc:MovieClip,
bytesLoaded:Number, bytesTotal:Number) {
this.pBar.bar_mc._xscale = Math.round(bytesLoaded/bytesTotal*100);
};
//Actions to do when loading is complete
mclListener.onLoadComplete = function(target_mc:MovieClip) {
this.pBar.removeMovieClip();
};
//Actions to do when load is initiated (first frame)
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc._xscale = 12;
target_mc._yscale = 12;
};
//Create a container for the image to load into
var movImage:MovieClip = this.createEmptyMovieClip("image_mc"+i,
this.getNextHighestDepth());
movImage.createEmptyMovieClip("holder", 1);
//Create a object for the movieclip loader & add the listners to it (defined
above)
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
//Load the actual image

image_mcl.loadClip("http://www.url.be/inside/images"+strLocation+"/image"+i+".
jpg", movImage.holder);
//Position the image
movImage._x = 143*(i%4);
movImage._y = yMovie;
//Assign code to the images
movImage.onRollOver = function() {
this.swapDepths(100);
this.holder._xscale = 25;
this.holder._yscale = 25;
};
movImage.onRollOut = function() {
this.holder._xscale = 12;
this.holder._yscale = 12;
};
movImage.onRelease = function() {
//
};
}
}
Re: Function question gijbelsy
9/7/2005 9:12:00 PM
pBar is a movieclip, loaded erlier in the movie (as you can see in the code
attached).
When I remove the function tag, in the beginning of the code, and copy paste
it to the 1st frame of the timeline, everything works. But when I put it inside
a function tag, to call this code later on (lets say with a button) then
suddenly the removemovieclip doesn't work anymore.
Re: Function question Jeckyl
9/8/2005 12:00:00 AM
From what you've shown, I cannot see anything wrong ... I suggest you add
some tracing .. eg

mclListener.onLoadComplete = function ( target_mc : MovieClip )
{
trace("onLoadComplete called with
this.pBar=<"+this.pBar+">");
this.pBar.removeMovieClip();
};

And see if the onLoadComplete is actually called at all, and if this.pBar
has the value you expect.

Jeckyl

Re: Function question Jeckyl
9/8/2005 12:00:00 AM
It could be that getNextHighestDepth is returning bad values (it does that
if you use certain components).

If a depth is too high, then removeMovieClip fails.

Try tracing

trace(this.pBar+" is at depth "+this.pBar.getDepth());

(hope I got the sytnax correct there)
--
Jeckyl

Re: Function question gijbelsy
9/8/2005 9:26:40 AM
Here is the output:
**********************************************************************
onLoadComplete called with this.pBar=<_level0.ProgressBar1>
onLoadComplete called with this.pBar=<_level0.ProgressBar0>
onLoadComplete called with this.pBar=<_level0.ProgressBar2>
onLoadComplete called with this.pBar=<_level0.ProgressBar3>
onLoadComplete called with this.pBar=<_level0.ProgressBar4>
onLoadComplete called with this.pBar=<_level0.ProgressBar5>
onLoadComplete called with this.pBar=<_level0.ProgressBar7>
onLoadComplete called with this.pBar=<_level0.ProgressBar8>
onLoadComplete called with this.pBar=<_level0.ProgressBar6>
onLoadComplete called with this.pBar=<_level0.ProgressBar9>
onLoadComplete called with this.pBar=<_level0.ProgressBar11>
onLoadComplete called with this.pBar=<_level0.ProgressBar10>
onLoadComplete called with this.pBar=<_level0.ProgressBar13>
onLoadComplete called with this.pBar=<_level0.ProgressBar14>
onLoadComplete called with this.pBar=<_level0.ProgressBar12>
onLoadComplete called with this.pBar=<_level0.ProgressBar15>
onLoadComplete called with this.pBar=<_level0.ProgressBar17>
onLoadComplete called with this.pBar=<_level0.ProgressBar18>
onLoadComplete called with this.pBar=<_level0.ProgressBar16>
onLoadComplete called with this.pBar=<_level0.ProgressBar19>
onLoadComplete called with this.pBar=<_level0.ProgressBar20>
************************************************************************

What makes this even more strange and thats why I'm seriously doubting if it
has anything to do whith the paths. The code listed in 'onLoadProgress' has the
same path (this.pBar) but works perfectly. The movieclip is scaled nicely.
Re: Function question gijbelsy
9/8/2005 9:50:18 AM
Well I've found the problem myself... but I really don't have an explenation why...
this works:
this.pBar.unloadMovie();


and this doesn't
AddThis Social Bookmark Button