Showing posts with label flash. Show all posts
Showing posts with label flash. Show all posts

Saturday, April 05, 2008

Flash Preloader

I've been wanting to learn to do this for a while. I needed a preloader for a Flash slideshow I made of some hi-res jpegs for my family because the swf file was about 7.6 MB. Anyway, this one is really good, simple. The actionscript actually makes sense to me:
myLoaded = Math.round(getBytesLoaded());
myTotal =
Math.round(getBytesTotal());
myPercent = myLoaded/myTotal;
myBar.
_width = myPercent*150;
myText =
Math.round(myPercent*100)+"%";
if (myLoaded == myTotal) {
gotoAndPlay(3);
}
else {
gotoAndPlay(1);
}


The only thing I changed is the command "gotoAndPlay," which in the original was "gotoAndStop." The preloader is on frames 1 and 2 and the slideshow starts on frame 3, so as soon as the loaded bytes = the total bytes (it's fully loaded) it goes to and plays frame 3. Then at the end of the slideshow I put the command gotoAndPlay(3) so it would loop the slideshow.

Wednesday, April 02, 2008

Programming buttons in Flash 8

I don't use Flash that often and when I do I always find that programming buttons is a little different each new version of Flash--different enough that I find it really frustrating figuring something out that should be easy. Well, here are the things I learned about making buttons on a recent project.
  • Mouse events, like onPress and onRelease, only work inside buttons, even if the event doesn't involve the button. If you want to script events for key presses, for example, the script has to be on an (invisible) button.
  • Here's the script for a button press :
on(Release){
gotoAndPlay("Scene 2", 1);
}
  • Or if you want the button to open a URL (Take out the blank if you want the same window.):
on(Release){
getURL("http://somewebsite.com", "_blank");
}
  • Here's the script for a key press event:
on (release, keyPress "") {
_root.nextFrame();
this.gotoAndStop();
}

It's not that hard to find these scripts on forums but it seems like it's such a standard thing to use in a Flash animation that it should be easier to find out how to do within the Flash help itself.