actionscript help for a non programmer who wants to do it the right way
June 29, 2006 11:11 AM
Subscribe
OK. So I have five movie clips on the stage named b1 - b5. When the user clicks on one the other four need to gotoAndPlay. I could write a function for one object then cut and paste and just change the names, but that seems inelegant. What I think I need to do is generate an array containing the five objects, then, when the user clicks on one of them, that one is removed from the array and triggers a function that loops through the remaining clips in the array and does the goto. Does that make sense? And if so, how would I do it? And if not, what is a better way? In other words, user clicks on movie named b1 and b2-b5 do something. user clicks on movie named b3 and b1,b2,b4, and b5 do something. Thanks!
OH. One other thing. After the stage is cleared of all but one clip (that's the animation that the goto goes to) the remaining clip must play an animation.
My level of experience ranks slightly below that of chipmunk's, so any example code w/ comments would be greatly appriciated.
posted by Grod to work & money (22 comments total)
class clip {
public:
void play() ;
void gotoandPlay() ;
} ;
clip arrayOfClips[ 5 ] ;
void onClick( int whichClip ) {
const int clipCount = arrayOfClips / arrayOfClips[ 0 ] ;
if( whichClip >= clipCount )
throw std::out_of_range( "There aren't that many clips, mr. programer" ) ;
for( int i = 0 ; i < ; ++i ) br> if( i != whichClip )
arrayOfClips[ i ].gotoandPlay() ;
arrayOfClips[ whichClip ].play() ;
}
I don't know what language you're using, but this C++ code should be easy enough to follow. Of course, the definition of class clip is left to you; I'm "assuming" the clips don't need to be initialized, which of course isn't true.
Summary: you don't need to remove stuff from the array, you just need to call gotoAndPlay on all clips but the one selected, and then call play on that one.>
posted by orthogonality at 11:34 AM on June 29, 2006