PDA

View Full Version : Using event methods with attachMovie?


InvaderPiotr
02-25-2003, 04:33 PM
As an exercise, I'm trying to build a menu system like the one at http://www.teknision.com.

So, let's assume that I'm working on just one 'slice' of the navigation, a series of movie clips with previous and next arrows to navigate between them, with easing done in AS using deltas.

Now, I'm using a loop to build the MCs horizontally and a couple of buttons for scrolling back and forth, and that works fine, but I can't figure out how to do is fade each MC in sequentially - have them fade in one after the other (or delay it the way Teknision's done it - as they come on, they appear one after the other with a pause in between each one).

I thought I could try an alpha fade on the MC as it's attached inside the loop like so:


for (i=0; i<=_root.clipamount; i++){

//make clips
this.attachMovie ("daclip", "daclip"+i, i+1);
this["daclip"+i]._x = this["daclip"+i]._width * i + (i*5);
this["daclip"+i]._y = 80;

//get width of clip
this["daclip"+i].clipwidth = this["daclip"+i]._width;

//trying to fade the clip... what am I doing wrong?
this["daclip"+i].onLoad = function() {
this._alpha = 1;
}

this["daclip"+i].onEnterFrame = function () {
this._alpha += 1;
}

}


...but that doesn't work. If I put a fade into the blank MC that I use to build the menu it obviously fades all of them in at the same time.

What's the flaw in my logic?

Many thanks,

Piotr

Billy T
02-25-2003, 08:55 PM
Originally posted by InvaderPiotr

...but that doesn't work.

what does it do? The are problems with the onLoad event. You might want to change

this["daclip"+i].onLoad = function() {
this._alpha = 1;
}

to

this["daclip"+i]._alpha = 1;

cheers

lbower
02-27-2003, 02:57 PM
Would somehow implementing the setInterval() function work?

InvaderPiotr
02-27-2003, 04:12 PM
It seems to me that that's what I should be trying to do... using timers in loops, as I naively first thought of doing, doesn't work.

I found an example of someone covering the screen in MCs with each one being delayed slightly here (http://www.actionscript.org/forums/showthread.php3?s=&threadid=22878) (posted towards the bottom by Freddycodes), but my AS skills are still limited enough for me to not fully understand what's happening there and adapt it to making a single row of MCs that attach to another, blank MC whose position I can then ease back and forth with a set of buttons. Hopefully I can figure it out... ah, perseverance.

-p.

Billy T
02-27-2003, 09:47 PM
setInterval should work fine

i=0;
function makeClip(){
//make clip
this.attachMovie ("daclip", "daclip"+i, i+1);
this["daclip"+i]._x = this["daclip"+i]._width * i + (i*5);
this["daclip"+i]._y = 80;

//get width of clip
this["daclip"+i].clipwidth = this["daclip"+i]._width;

//trying to fade the clip... what am I doing wrong?
this["daclip"+i].onLoad = function() {
this._alpha = 1;
}

this["daclip"+i].onEnterFrame = function () {
this._alpha += 1;
}
i++;
if(i>_root.clipamount){
clearInterval(makeMenu);
}
}
menuMaker=setInterval(makeClip,1000);

something like that anyway

lbower
02-28-2003, 01:28 PM
Okay, here's a demo of what I think you're trying to accomplish. I didn't try using ActionScript to increase the alpha level of each movieclip; instead I used a tweening affect in each movie.

Hope this helps!