Groups | Blog | Home
all groups > flash (macromedia) > november 2003 >

flash (macromedia) : Newbie needs help - Set Interval



PV
11/13/2003 11:13:57 PM
I am trying to apply a fade-in to a photo via the setInterval but all it does is go through one evaluation, and the image is displayed on the screen with an alpha of 15. It doesn't fade-in the way I want.

All code is on Frame 1 of my script layer on the main timeline.

What am I doing wrong?
Much thanks for any insight...
Paul



// Here's my function

function fadeIn(myClip) {
if (myClip._alpha>=100) clearInterval (intervalID);
myClip._alpha+=15;
updateAfterEvent();
}
intervalID=setInterval (fadeIn,100);



// ...this creates my container clip and loads the image

this.createEmptyMovieClip ("containClip",1);
containClip_x=0;
containClip._y=50;
containClip._alpha=0;
containClip.loadMovie ("IMG_1896.jpg");



//...and this calls my function and passes the clip's name

fadeIn(containClip);

brian_griffith
11/14/2003 12:02:09 AM
Hello, I am a bit of a newbie aswell ... and I could be wrong ... but when you call the function ... you need to use onClipEvent (enterFrame) { so it checks for the alpha everytime the frame refreshes (12 fps or whatever) ... again ... I could be wrong ... but if I'm not I hope this helps!

Sincerely,
Brian Griffith

PV
11/14/2003 12:46:15 AM
Thanks, Brian...but actually the setInterval method eliminates the need to be tied down to your movie's frame rate. You can execute whatever you'd like to do (motion, alpha changes, etc...) at a rate much faster than an enterFrame event would allow.

And I figured out what I was doing wrong...

I was trying to call the fadeIn function the wrong way. What I needed to do was call it this way and place it below the part of my code that creates the containClip:

intervalID=setInterval (fadeIn,100,containClip);


and eliminate the following line:

fadeIn(containClip);

You see Brian, what my setInterval code says is to call the function (fadeIn), every 100 milliseconds, and use the containClip as the argument to the function.

setInterval is great...it eliminates the need for timeline looping, event frame looping/repeating, etc...

The Big Giant Head
11/14/2003 12:56:54 AM
why use a function for this ?
From what you've said you don't need to.
File size won't be increased by code.
Do it the simple way.
PV
11/14/2003 2:40:01 AM
Hi Giant Head...

I'm using a function so I can re-use generic code...the function will allow me to fade-in any mc I want...

Is there something I'm missing? How would you have gone about it?

I'm curious...

Thanks!

AddThis Social Bookmark Button