Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function called after mc load error & variable question

Status
Not open for further replies.

jbezzina

MIS
May 4, 2004
46
0
0
MT
Hi,

I'm currently working on a dynamic photo gallery. I am loading 20 images on screen in 20 separate movie clips. But if the total number of photos is less than 20, I'm obviously getting an error when the picture being asked is not found. What I need is to load a blank image after the first error msg is reported and in the remaining movie clips:

What I think I need is to call a function on load error. How is this done ?

Here is part of the code I'm using:

for (i=1; i<21; i++) {
myMCL.loadClip("gallery/tn_photo"+picNum+".jpg", this["thumbHolder"+i]);
picNum++;

____________________________

Also, I read that a variable within a function is treated differently from one outside. It seems that you can have 2 variables with the same name but located in different function and these will not be related.

But what if I need to call a variable that was set and is being maintained outside my function or in a different function, how is this done?

Thanks !!
 
The second qustion is about variable scope. Basically any variable declared inside a function is local to that function and doesn't exist outside of it.

To keep things clear you can use the keywords var and _global:

var creates a local variable which is destroyed as soon as the function it was declared in is exited.

_global creates a vairable which can be accessed from anywhere in the movie.

In MX2004 you can trap errors within class structures but the easiest way to fix the problem is either to actually have blank jpgs in the directory which can be loaded in or to actually set up in the code how many jpgs you need to load dynamically, e.g. you could use an array:

Code:
for (var i=0;i<imagesArray.length;i++){
 
Hi wangbar. Thanks for your your answer on variables. I hope that thanks to this I would be able to solve my first problem ( I rather not use an arrays since I'm quite new to these)
 
What Wangbar rightly suggests is that either you know how many images you are going to have or you don't. If you don't have a fixed number you need to use a variable to define how many there are.

You don't have to use an array to do that, but it is the easiest way if you are not using an outside datasource (and sometimes if you are). This will prevent you from getting the error to begin with (so you won't need to handle it).

Conversely if you know how many there are you should never get an error :)

Great definition of Variables Wangbar!

Wow JT that almost looked like you knew what you were doing!
 
Thanks – to all of you that helped and offered advise.. Mission (almost) accomplished. I might post the URL in here in a day or two after I fine-tune a few things.

BTW... say you have this situation:

Code:
var count:Number;

count = Math.round(2.2+3.1);
trace(count); // will return 5

is there a way to round up to the nearest (next) whole number? at the moment I'm using the following:

Code:
var count:Number;
var extra:Number = .5;

count = Math.round(2.2+3.1+extra);
trace(count); // will return 6

It works but... It looks funny somehow.

Once again... THANKS !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top