Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-18-2003, 07:33 PM   #1
sendres
Registered User
 
Join Date: Aug 2003
Location: Oak Park, IL
Posts: 29
Send a message via AIM to sendres Send a message via Yahoo to sendres
Question How to copy loaded image from one mc to another?

How do I copy an image loaded into a movie clip into another movie clip?

I have written the following code to produce a slide show effect, complete with fade-in and fade-out. It works fine when I run it from a local directory. When I run from my web server, however, it takes too long to load the next external jpeg. As a result, I get more of a cut-in, fade-out effect.

I'm sure the problem is that I wait until I'm finished with my first picture before I load in the next one. My initial thought is to load the next image in the background while the first image is on screen. So I'd like to add in another movie clip to queue the next picture. In other words:

1. load the first pic
2. fade in the first pic
3. start loading the second pic while the first is static on screen
4. fade out the first pic
5. copy the second pic into the holder for the first pic
6. repeat steps 2--5 indefinitely

Here's my code:

ActionScript Code:
/////////////////////////////////////////////////////////// // This component uses a series of                       // // consecutively numbered image files located in the     // // subdirectory '/right' to create a slideshow effect in // // an empty movie clip. For each image, it fades the     // // image in, waits eight seconds, then fades the image   // // out. You must specify the number of images in the     // // subdirectory using the maxNum parameter below. For    // // example, if the first image is 'right0.jpg' and the   // // last is 'right9.jpg', then maxNum is set to 10. Note: // // image file numbering must always start with zero!     // /////////////////////////////////////////////////////////// // number of image files (numbered 0...maxNum - 1) var maxNum = 6; // create an empty movie clip to hold the image this.createEmptyMovieClip ("rightClip", 1); // select the initial picture at random var picNum = Math.floor(maxNum * Math.random()); var fileName = "right/right" + picNum +".jpg"; // set the starting alpha to transparent var clipAlpha = 0; this["rightClip"]._alpha = clipAlpha; // load the image into the empty movie clip this["rightClip"].loadMovie(fileName); // initialize the other variables var direction = "up"; var counter = 0; /////////////////////////////////////////////////////////// // function onEnterFrame // // This function fades the image in, holds it on screen, // or fades it out depending on the setting of the // direction variable. /////////////////////////////////////////////////////////// this.onEnterFrame = function() {     ///////////////////////////////////////////////////////     // fade in     ///////////////////////////////////////////////////////      if (direction == "up")     {         // increase the opacity         clipAlpha += 5;         this["rightClip"]._alpha = clipAlpha;                 // hold if at maximum opacity         if (clipAlpha >= 100) {         this["rightClip"]._alpha = 99;         direction = "hold";         }     }         //////////////////////////////////////////////////////////     // hold     //////////////////////////////////////////////////////////     else if (direction == "hold")     {         // increment the counter         counter++;                 // fade out if time has elapsed         if (counter == 160)         {             direction = "down";         }           }         //////////////////////////////////////////////////////////     // fade out     //////////////////////////////////////////////////////////     else if (direction == "down")     {         // decrease the opacity         clipAlpha -= 5;         this["rightClip"]._alpha = clipAlpha;                 // set up for the next image if at minimum opacity         if (clipAlpha <= 0)         {             this["rightClip"]._alpha = 0;             direction = "up";             counter = 0;             picNum = (picNum + 1) % maxNum;             fileName = "right/right" + picNum +".jpg";             this["rightClip"].loadMovie(fileName);         }     } }

Any suggestions?
sendres is offline   Reply With Quote
Old 08-18-2003, 11:39 PM   #2
Colin Campbell
Senior Member
 
Join Date: Jun 2003
Posts: 2,090
Default

uh, I'll try and help you my best as no one else has posted.

ActionScript Code:
this["rightClip"]._alpha = 0; this["rightClip"].unloadMovie(fileName);                         direction = "up";                         counter = 0;                         picNum = (picNum + 1) % maxNum;  fileName = "right/right" + picNum +".jpg";                         this["rightClip"].loadMovie(fileName);

Try that... lets see if we can get this topic started for you.
Colin Campbell is offline   Reply With Quote
Old 08-19-2003, 11:26 AM   #3
sendres
Registered User
 
Join Date: Aug 2003
Location: Oak Park, IL
Posts: 29
Send a message via AIM to sendres Send a message via Yahoo to sendres
Smile I found another way

Instead of loading just the next pic, I create empty movie clips for each pic. I load the first pic, fade it on screen, and while it's displayed I load the second pic. While the second is on screen I load the third, etc. Once each pic has been loaded, I set a loadDone flag to true, so I don't try to reload the pic I already have:
ActionScript Code:
// number of image files (numbered 0...maxNum - 1) var maxNum = 6; // create empty movie clips to hold the images for (var i = 0; i < maxNum; i++) {     this.createEmptyMovieClip ("rightClip" + i, i);     this["rightClip" + i]._alpha = 0;     this["rightClip" + i]._visible = false; } // select the initial and terminal pictures at random var lastPicNum = Math.floor(maxNum * Math.random()); var picNum = (lastPicNum + 1) % maxNum; var fileName = "right/right" + picNum +".jpg"; // set the starting alpha to transparent var clipAlpha = 0; // load the first image into the empty movie clip this["rightClip" + picNum].loadMovie(fileName); // initialize the other variables var direction = "up"; var counter = 0; var loadDone = false; /////////////////////////////////////////////////////////// // function onEnterFrame // // This function fades the image in, holds it on screen, // or fades it out depending on the setting of the // direction variable. /////////////////////////////////////////////////////////// this.onEnterFrame = function() {     ///////////////////////////////////////////////////////     // fade in     ///////////////////////////////////////////////////////      if (direction == "up")     {         // make the clip visible         this["rightClip" + picNum]._visible = true;                 // increase the opacity         clipAlpha += 5;         this["rightClip" + picNum]._alpha = clipAlpha;                 // hold if at maximum opacity         if (clipAlpha >= 100)         {             this["rightClip" + picNum]._alpha = 99;             direction = "hold";                     // determine the next pic number             nextPicNum = (picNum + 1) % maxNum;                     // load the next pic if not already loaded             if (loadDone == false)             {                 fileName = "right/right" + nextPicNum +".jpg";                 this["rightClip" + nextPicNum].loadMovie(fileName);                                 // see if the last pic was loaded                 if (nextPicNum == lastPicNum)                 {                 loadDone = true;                 }             }         }     }         //////////////////////////////////////////////////////////     // hold     //////////////////////////////////////////////////////////     else if (direction == "hold")     {         // increment the counter         counter++;                 // fade out if time has elapsed         if (counter == 160)         {             direction = "down";         }           }         //////////////////////////////////////////////////////////     // fade out     //////////////////////////////////////////////////////////     else if (direction == "down")     {         // decrease the opacity         clipAlpha -= 5;         this["rightClip" + picNum]._alpha = clipAlpha;                 // set up for the next image if at minimum opacity         if (clipAlpha <= 0)         {             this["rightClip" + picNum]._alpha = 0;             this["rightClip" + picNum]._visible = false;             direction = "up";             counter = 0;             picNum = nextPicNum;         }     } }
sendres is offline   Reply With Quote
Old 08-19-2003, 11:33 AM   #4
sendres
Registered User
 
Join Date: Aug 2003
Location: Oak Park, IL
Posts: 29
Send a message via AIM to sendres Send a message via Yahoo to sendres
Thumbs up Also, thanks for the jump start

Hey, colin14, thanks for trying help. I'm never sure why one message post will get viewed/replied and another doesn't. It almost seems that the more ambiguous the topic, the greater chance for successful replies!

Anyway, thanks again for trying to "get this party started." It's much appreciated!
sendres is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:45 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.