View Full Version : creating a function

03-20-2006, 06:27 AM
hi all,

I have for like 10 mc's in my scene (there will come more, about 270 finally)
now i have this code ( darzak helped me to make it :P, on this same forum ):

onClipEvent (enterFrame)
var bHit = this.hitTest(_root.area);
if (bHit && picture_mc1 == undefined)

xwidth = this._width;
yheight = this._height;

preload_resize("tiles/r01/001.jpg", picture_mc1, xwidth, yheight);


} else if (!bHit && picture_mc1 != undefined){

now i have to add this whole script to EACH mc, i was thinking of make a function of it and put this in the main layer and then in each moveclip type in something like:

getimg("tiels/r01/001.jpg", "picture_mc1")

but dunno how to create this fuunction??
does someone have a clue?

ur help will be really really appreciated :D

03-20-2006, 06:45 AM
function getImage(source:String, dest:String, width:Number, height:Number)
if (this[dest] == undefined) this.createEmptyMovieClip(dest, this.getNextHighestDepth());
preload_resize(source, this[dest], width, height);

03-20-2006, 06:47 AM
function imgthing(z:String, v:String) {
this.createEmptyMovieClip(z, this.getNextHighestDepth());
preload_resize(v, picture_mc1, xwidth, yheight);
trace(z + " + " + v);
imgthing("picture_mc1", "tiles/r01/001.jpg");

03-20-2006, 07:24 AM
thanks for the reply both of you,, but i don't works.. what about the var bHit ??

it doesnt load the img

03-20-2006, 11:46 AM
hi all,
the function doesnt work.. the images arent loading ..
so can someone help me please??

i have added the fla file..! :D
any help would be appreciated!!!

03-20-2006, 04:09 PM
there's an error inside your function: it should readfunction getImage (source:String, dest:String, width:Number, height:Number) {
this.onEnterFrame = function () {
var bHit = this.hitTest (_root.area);
if (bHit && this[dest] == undefined) {
this.createEmptyMovieClip (dest, this.getNextHighestDepth ());
preload_resize (source, this[dest], width, height);
} else if (!bHit && dest != undefined) {
this.dest.removeMovieClip ();

03-20-2006, 04:16 PM
thanks for your reply.
unfortunately it doesn't works..
apperantly this[dest] is undefined cuz i've added a tracee function

if (bHit && this[dest] == undefined) {

it wont trace hit even when its hit..

03-20-2006, 04:35 PM
nah that wasnt the problem.. i have added _parent.loadImage
then it did work!

03-20-2006, 04:41 PM
Is bHit a Boolean? otherwise if it is not, your logic is asking the wrong question (basically if bHit==true). If you are trying to see if bHit and this.dest is undefined then you would use:

if (bHit == undefined && this.dest == undefined) {

It is all in your logic. I'm not sure all what you are doing (I couldn't get your FLA to open), but you need to check over your logic and make sure it makes more sense. Try doing one simple logic statement at a time to troubleshoot.