PDA

View Full Version : fmx error



aquaman
November 5th, 2003, 07:01 PM
can someone please tell me what iīm making wrong:

for (i=1; i<=8; i++) {
attachMovie("mc", "m"+i, i);
_root["m"+i]._x = 10;
_root["m"+i]._y = 10+yPos;
yPos += 70;
_root["m"+i]._width = 50;
_root["m"+i]._height = 50;
_root["m"+i].preload("images/m"+i+".jpg", 40, 50, 50);
//loadimages
_root["m"+i].onPress = function() {
loadMovie(this._name+".jpg", _root.content_mc);
};
}
//iīm using this to attach an mc 8 timesto preload some images to it, but the press event dosenīt work. have I wroted a mistake, I canīt figure it out (preload is a proto) and he works fine, the error only occurs when i click each image, he says he dosenīt find the image

thanks

kode
November 6th, 2003, 01:33 AM
You're surely assigning the onPress event handler before the image has been loaded.

Post the code for the preload method. ;)

aquaman
November 6th, 2003, 04:34 AM
MovieClip.prototype.preload = function(image, barWidth, imgWidth, imgHeight) {
// Set variables
var barWidth = barWidth == undefined ? 100 : barWidth;
var imgWidth = imgWidth == undefined ? 0 : imgWidth;
var imgHeight = imgHeight == undefined ? 0 : imgHeight;
// Create mc's
this.createEmptyMovieClip("PH_mc", 0);
this.createEmptyMovieClip("updater_mc", 1);
this.createEmptyMovieClip("bar_mc", 2);
this.createEmptyMovieClip("text_mc", 3);
// Scale bar
this.bar_mc._xscale = 1;
// Make preloader bar
with (this.bar_mc) {
beginFill(0xFF0000, 100);
lineTo(barWidth, 0);
lineTo(barWidth, 1);
lineTo(0, 1);
lineTo(0, 0);
}
// Text format
this.format = new TextFormat("Arial", 10, 0xFFFFFF, false, false, false, null, null, "center");
// Make preloader text
with (this.text_mc) {
createTextField("preload_txt", 0, 0, 0, barWidth, 0);
with (preload_txt) {
setNewTextFormat(this.format);
border = true;
borderColor = 0xFFFFFF;
text = " ";
selectable = false;
}
}
// Set bar mc and text mc dimensions position
this.text_Height = this.text_mc.preload_txt.textHeight+2;
this.text_mc.preload_txt._height = this.text_Height;
this.bar_mc._height = this.text_Height;
// Set bar mc and text mc positions
if (imgWidth != 0) {
this.bar_mc._x = this.text_mc._x=imgWidth/2-barWidth/2;
}
if (imgHeight != 0) {
this.text_mc._y = imgHeight/2-this.text_mc._height/2;
this.bar_mc._y = imgHeight/2-this.bar_mc._height/2+1;
}
// Load image
this.PH_mc.loadMovie(image);
// Get updater running
this.updater_mc.onEnterFrame = function() {
this.Loaded = this._parent.PH_mc.getBytesLoaded();
this.Total = this._parent.PH_mc.getBytesTotal();
this.Percent = Math.ceil((this.Loaded/this.Total)*100);
if (this.Loaded != this.Total || this.Total<=0) {
this.Percent = this.Total == 0 ? 0 : this.Percent;
this._parent.text_mc.preload_txt.text = this.Percent+"%";
this._parent.bar_mc._xscale = this.Percent;
trace(this.Percent+" %");
} else {
this._parent.text_mc.preload_txt.text = this.Percent+"%";
this._parent.bar_mc._xscale = this.Percent;
delete this.onEnterFrame;
this._parent.bar_mc.removeMovieClip();
this._parent.text_mc.removeMovieClip();
this.removeMovieClip();
}
};
};

///////////////////thanks for helping

kode
November 6th, 2003, 05:15 AM
Ok... that's weird. :-\

The code seems to be fine, it shouldn't mess up the event the handler. Have you tried a trace() to check if the event handler is being called?

_root["m"+i].onPress = function() {
trace(this._name);
loadMovie(this._name+".jpg", _root.content_mc);
};
PS. I edited your post. Next time, please use the ActionScript tag to show your code. :P

aquaman
November 7th, 2003, 02:36 AM
hi
dosenīt work, i really donīt understand why is this, do you know a other preload proto whit alpha maybe

kode
November 7th, 2003, 02:54 AM
Why don't you attach your FLA? It would make things easier for me. ;)

And by alpha... do you mean to fade in the image?