PDA

View Full Version : onLoadstart, onLoadInit or unLoad help ?


Navarone
08-28-2005, 02:39 PM
When using these events, which one has presedence? In the following code I am having trouble getting the _root.timer_txt.text = "Loading....";, to display. Here is what happens,

When I first start my movie and I click on the button using the c_mc.onRelease = function(), the loading text appears as desired, before the thumbnail images appear.

If I click on the button again, there is a delay before the loading text appears. It's like the old images are being flushed from the memory before the new images can load.

Is there some way to trap a unLoas event or at least display some text message to let the user know whats happening?

I was going to post the fla, but it's to big to zip up so I posted the code instead.

Any help appreciated.



var pictures:mx.containers.ScrollPane;
pictures.contentPath = 'Holder_mc';
// reset text items
_root.zoom_txt.autoSize = true;
_root.zoom_txt.text = "0"+"%";
_root.zoom_in.enabled = false;
_root.zoom_out.enabled = false;
_root.who_btn.enabled = false;
_root.whois_mc._visible = false;
//
// load btn_ding
bgSound = new Sound(MyMusic_mc);
bgSound.loadSound("btn_ding.mp3", event);
// set variables to remember the orginal scale
this.zoom_out.onPress = function() {
if (pictures.content.myLoader.scaleX<=25) {
this.zoom_out.enabled = false;
bgSound.start();
} else {
pictures.content.myLoader.scaleX -= 25;
pictures.content.myLoader.scaleY -= 25;
//trace(Math.floor(pictures.content.myLoader.scaleX) );
_root.zoom_txt.text = +Math.floor(pictures.content.myLoader.scaleX)+"%";
}
pictures.invalidate();
};
this.zoom_in.onPress = function() {
if (pictures.content.myLoader.scaleX>=500) {
this.zoom_in.enabled = false;
bgSound.start();
} else {
pictures.content.myLoader.scaleX += 25;
pictures.content.myLoader.scaleY += 25;
//trace(Math.floor(pictures.content.myLoader.scaleX) );
_root.zoom_txt.text = +Math.floor(pictures.content.myLoader.scaleX)+"%";
}
pictures.invalidate();
};
// create thumbnail images
var MAX_WIDTH:Number = 65;
var MAX_HEIGHT:Number = 65;
//
var mclListener:Object = new Object();
mclListener.onLoadStart = function(mc:MovieClip) {
//mc1.startTimer = getTimer();
_root.timer_txt._visible = true;
_root.timer_txt.text = "Loading....";
};
mclListener.onLoadInit = function(mc:MovieClip) {
_root.timer_txt._visible = true;
_root.timer_txt.text = "Loading....";
// set variables to keep the original image dimensions
var xw = mc._width;
var xh = mc._height;
//trace(xw);
//trace(xh);
// where image width is greater than image height
if (mc._width>mc._height) {
mc._width = MAX_WIDTH;
mc._height = (mc._height*MAX_WIDTH)/xw;
// center image
mc._y = (75-mc._height)/2;
}
//where image height is greater than image width
if (mc._height>mc._width) {
mc._height = MAX_HEIGHT;
mc._width = (mc._width*MAX_HEIGHT)/xh;
mc._x = (75-mc._width)/2;
}
_root.timer_txt._visible = false;
};
//
MyLoadVars = new LoadVars();
MyLoadVars.load("image_txt_files/folders.txt");
MyLoadVars.onLoad = function(success) {
if (success) {
var c_mc:MovieClip;
Rc = this["Rc"];
//trace(Rc);
for (i=0; i<=Rc-1; i++) {
c_mc = _root.scrollPane.content.attachMovie("Folder_mc", "clip"+i, i, this.getNextHighestDepth());
c_mc.name.autoSize = true;
c_mc.name.text = this["Folder"+i];
c_mc._x = 5;
c_mc._y = 5+(i*20);
c_mc.i = i;
c_mc.location = this["Folder"+i];
c_mc.onRelease = function() {
_root.timer_txt.autoSize = true;
_root.timer_txt.text = "Loading....";
_root.t_txt.text = "";
_root.who_btn.enabled = false;
// set zoom buttons
_root.zoom_in.enabled = false;
_root.zoom_out.enabled = false;
//set instruct text
_root.instruct_txt.autoSize = true;
_root.instruct_txt.multiline = true;
_root.instruct_txt.text = "Scroll through the thumb nail images and click on that image to see it in the picture window.";
_root.whois_mc._visible = false;
pictures.refreshPane();
thumbs.refreshPane();
// this repopulates the scrollpane at runtime
for (i=0; i<=6; i++) {
t_mc = _root.thumbs.content.attachMovie("thumb_mc", "tip"+i, i, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(i*80);
t_mc.i = i;
thumbs.invalidate();
}
//
if (this.location == this.location) {
trace("test "+this.location);
var elf = this.location;
MyPicVars = new LoadVars();
MyPicVars.load("image_txt_files/"+elf+".txt");
MyPicVars.onLoad = function(success) {
if (success) {
//trace("success");
//trace(elf);
var t_mc:MovieClip;
Rc = this["Rc"];
for (i=0; i<=Rc-1; i++) {
t_mc = _root.thumbs.content.attachMovie("thumb_mc", "tip"+i, i, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(i*80);
//
_root["mc"+i] = new MovieClipLoader();
_root["mc"+i].addListener(mclListener);
_root["mc"+i].loadClip(+elf+"/"+this["pic"+i], t_mc.container_mc);
//
t_mc.i = i;
t_mc.location = this["pic"+i];
t_mc.onRelease = function() {
// erta is the thumbnail image you clicked on
erta = this.location;
// set text boxes to empty
_root.whois_mc.whois_txt.text = "";
_root.whois_mc.pic_date.text = "";
_root.whois_mc.LtoR.text = "";
_root.whois_mc.aka.text = "";
// load photo information
MyTextVars = new LoadVars();
MyTextVars.load("image_txt_files/photo.txt");
MyTextVars.onLoad = function(success) {
if (success) {
Rc = this["Rc"];
//trace(erta)
//trace("loaded");
for (i=0; i<=Rc-1; i++) {
//trace(Rc);
//trace(this["image"+i]);
if (this["image"+i] == erta) {
//trace(this["image"+i]);
_root.whois_mc.whois_txt.autoSize = true;
_root.whois_mc.pic_date.autoSize = true;
//_root.whois_mc.LtoR.autoSize = true;
_root.whois_mc.aka.autoSize = true;
_root.whois_mc.whois_txt.text = this["whois_text"+i];
_root.whois_mc.pic_date.text = this["pic_date"+i];
_root.whois_mc.LtoR.text = this["LtoR"+i];
_root.whois_mc.aka.text = this["aka"+i];
} else {
//do nothing
}
}
}
};
//
_root.zoom_in.enabled = true;
_root.zoom_out.enabled = true;
_root.who_btn.enabled = true;
_root.zoom_txt.text = "100"+"%";
_root.instruct_txt.text = "You can navigate the picture by using the zoom buttons or scroll bars as they appear or drag your mouse to preview the picture.";
_root.whois_mc._visible = false;
//load image into pictures scroll pane
pictures.content.myLoader.contentPath = +elf+"/"+this.location;
// reset the images to 100%
pictures.content.myLoader.scaleX = 100;
pictures.content.myLoader.scaleY = 100;
// redraw component only when changes occur
pictures.invalidate();
};
//
thumbs.invalidate();
}
} else {
trace("not loaded");
}
};
} else {
trace("not loaded");
}
};
scrollPane.invalidate();
}
} else {
trace("not loaded");
}
};

cancerinform
08-28-2005, 03:08 PM
I don't say it loud but I have abondaned the MovieClipLoader class. It is too difficult to control (see your thread). Good old onEnterFrame monitoring the loading of anything works best for me.

Navarone
08-28-2005, 06:43 PM
Could you elaborate? How would I redo my code? Anything at this point would be better then what I have. :)

cancerinform
08-30-2005, 04:57 PM
Your code is pretty complex and difficult for me to get in but from what I see you have split up the MovieClipLoader into different parts outside and inside the button. Also you have functions inside the onLoad and even another onLoad. You are probably the only one who understands the code.

When i meant not to use the MovieClipLoader class I meant to have a setInterval or onEnterFrame event instead. Something like this to give you an idea but as I said your code is far too complex for me to understand.


// set variables to keep the original image dimensions
var xw = mc._width;
var xh = mc._height;
_root.onEnterFrame = function() {
_root.timer_txt._visible = true;
_root.timer_txt.text = "Loading....";
//trace(xw);
//trace(xh);
// where image width is greater than image height
if (mc._width>mc._height) {
mc._width = MAX_WIDTH;
mc._height = (mc._height*MAX_WIDTH)/xw;
// center image
mc._y = (75-mc._height)/2;
}
//where image height is greater than image width
if (mc._height>mc._width) {
mc._height = MAX_HEIGHT;
mc._width = (mc._width*MAX_HEIGHT)/xh;
mc._x = (75-mc._width)/2;
}
_root.timer_txt._visible = false;
};

Navarone
08-30-2005, 06:51 PM
Hey thanks, I see what you are saying.

Yeh my code is rather complex, I hesitated even posting it. Essentially, there are three scrollPane's instances on the stage, the first scrollPane, "Folder_mc", loads in a text file, I make buttons out of those text links.

The second scrollPane "thumbs", is just what it's for, it loads up thumbnail images when you press a text link in the first scrollPane. Rather than load seperate small images, I run my resize script. This dynamically resizes the loaded images and maintains aspect ratios.

The "Loading..." text shows up the very first time no matter how many images get loaded, it's when you click to load another set of images that the timing gets muddeled.

When you click on one of the thumbnails, the full size version is added to the last scrollPane "pictures". There are some text fields that are being generated along the way and the zoom in/out functions are stuck in there too.

Everything works really well except for the part I mentioned. I don't think the onLoadInit and onLoadStart are broadcasting the event like they should. I'm gona check out what you suggested thought. :)