Movie clip resize not working when image is loaded

  • clem_c_rock
  • Novice
  • Novice
  • clem_c_rock
  • Posts: 20

Post 3+ Months Ago

Hello,
I'm having some strange luck in building an image slide show. I load the image paths into an array from an XML
page and then step through the array elements w/ forward and back buttons.

I have an empty image clip on the stage where I create an empty movie clip inside each time a new image is loaded. I load the
image into the second movie clip like this:

Code: [ Select ]
_root.picsPage_mc.mc_pic_loader.mc_individual_pic_loader.unloadMovie();
_root.picsPage_mc.mc_pic_loader.createEmptyMovieClip( 'mc_individual_pic_loader', 1 );
_root.load_movie_and_stop( _root.picsPage_mc.mc_pic_loader.mc_individual_pic_loader, _root.photo_array[_root.photo_index].image, _root.picsPage_mc.mc_pbar, 'regular_load');
  1. _root.picsPage_mc.mc_pic_loader.mc_individual_pic_loader.unloadMovie();
  2. _root.picsPage_mc.mc_pic_loader.createEmptyMovieClip( 'mc_individual_pic_loader', 1 );
  3. _root.load_movie_and_stop( _root.picsPage_mc.mc_pic_loader.mc_individual_pic_loader, _root.photo_array[_root.photo_index].image, _root.picsPage_mc.mc_pbar, 'regular_load');



The load_movie_and_stop function is as follows:
Code: [ Select ]
function load_movie_and_stop( target_mc:MovieClip, movie_clip_to_load:String, p_bar:MovieClip, action:String )
{
     mc_loader._width = 0;
     mc_slider_bar.mc_drag_pan._x = 0;
              
     if( action != 'simple_load' )
     {
       p_bar._visible = true;
         p_bar.bar._width = 0;
    }    
                
     var mclListener:Object = new Object();
     mclListener.onLoadStart = function( target_mc )  
     {
         if( action != 'simple_load' && action != 'regular_load' ){ target_mc.stop(); } 
         if( action == 'load_and_play' ){ target_mc.play(); }
     }
    
     mclListener.onLoadInit = function( target_mc )
     {        
         _root.resize_movie_clip(target_mc, 160, 120, 250, 190);
         if( action == 'load_and_stop' ){ target_mc.stop(); }
     }
     
     mclListener.onLoadProgress = function( target_mc )
   {
         
     if( action != 'simple_load' )
         {
        percentLoaded = Math.floor( ( target_mc.getBytesLoaded()/target_mc.getBytesTotal() )*100);
        p_bar.bar._xscale = percentLoaded;
        p_bar.txt_percent = percentLoaded + "% loaded.";
         }
   }
     
     mclListener.onLoadComplete = function( target_mc ){ p_bar._visible = false; }

   var my_mcl:MovieClipLoader = new MovieClipLoader();
   my_mcl.addListener(mclListener);
   my_mcl.loadClip( movie_clip_to_load, target_mc );

}//___endFunc___                
  1. function load_movie_and_stop( target_mc:MovieClip, movie_clip_to_load:String, p_bar:MovieClip, action:String )
  2. {
  3.      mc_loader._width = 0;
  4.      mc_slider_bar.mc_drag_pan._x = 0;
  5.               
  6.      if( action != 'simple_load' )
  7.      {
  8.        p_bar._visible = true;
  9.          p_bar.bar._width = 0;
  10.     }    
  11.                 
  12.      var mclListener:Object = new Object();
  13.      mclListener.onLoadStart = function( target_mc )  
  14.      {
  15.          if( action != 'simple_load' && action != 'regular_load' ){ target_mc.stop(); } 
  16.          if( action == 'load_and_play' ){ target_mc.play(); }
  17.      }
  18.     
  19.      mclListener.onLoadInit = function( target_mc )
  20.      {        
  21.          _root.resize_movie_clip(target_mc, 160, 120, 250, 190);
  22.          if( action == 'load_and_stop' ){ target_mc.stop(); }
  23.      }
  24.      
  25.      mclListener.onLoadProgress = function( target_mc )
  26.    {
  27.          
  28.      if( action != 'simple_load' )
  29.          {
  30.         percentLoaded = Math.floor( ( target_mc.getBytesLoaded()/target_mc.getBytesTotal() )*100);
  31.         p_bar.bar._xscale = percentLoaded;
  32.         p_bar.txt_percent = percentLoaded + "% loaded.";
  33.          }
  34.    }
  35.      
  36.      mclListener.onLoadComplete = function( target_mc ){ p_bar._visible = false; }
  37.    var my_mcl:MovieClipLoader = new MovieClipLoader();
  38.    my_mcl.addListener(mclListener);
  39.    my_mcl.loadClip( movie_clip_to_load, target_mc );
  40. }//___endFunc___                


After the image is loaded into the movie clip, I then resize the image to be a specific width.

The image resizing is done w/ this function:
Code: [ Select ]
function resize_movie_clip(clip_loader_name:MovieClip, max_width:Number, max_height:Number )
{
   orig_width = clip_loader_name._width;
    orig_height = clip_loader_name._height;
    
    aspect_ratio = orig_width / orig_height;     
     
     if( (orig_width > max_width) || ( orig_height > max_height ) ) // If either dimension is too big...
    {
       if( orig_width > orig_height ) // For wide images...
       {
          new_width = max_height;
          new_height = new_width / aspect_ratio;
       } 
       else if( orig_width < orig_height )
       {
          new_height = max_height;
          new_width = new_height * aspect_ratio;
       }
       else if( orig_width == test_height )
       {
         new_width = max_width;
         new_height = max_width;
       }
       else { trace( "Error reading image size."); return false; }
   }
   else { new_width = orig_width; new_height = orig_height; }
     
   clip_loader_name._width = Math.round(new_width);
   clip_loader_name._height = Math.round(new_height);

};
  1. function resize_movie_clip(clip_loader_name:MovieClip, max_width:Number, max_height:Number )
  2. {
  3.    orig_width = clip_loader_name._width;
  4.     orig_height = clip_loader_name._height;
  5.     
  6.     aspect_ratio = orig_width / orig_height;     
  7.      
  8.      if( (orig_width > max_width) || ( orig_height > max_height ) ) // If either dimension is too big...
  9.     {
  10.        if( orig_width > orig_height ) // For wide images...
  11.        {
  12.           new_width = max_height;
  13.           new_height = new_width / aspect_ratio;
  14.        } 
  15.        else if( orig_width < orig_height )
  16.        {
  17.           new_height = max_height;
  18.           new_width = new_height * aspect_ratio;
  19.        }
  20.        else if( orig_width == test_height )
  21.        {
  22.          new_width = max_width;
  23.          new_height = max_width;
  24.        }
  25.        else { trace( "Error reading image size."); return false; }
  26.    }
  27.    else { new_width = orig_width; new_height = orig_height; }
  28.      
  29.    clip_loader_name._width = Math.round(new_width);
  30.    clip_loader_name._height = Math.round(new_height);
  31. };


Now, 98% of the time this works perfectly, but there is some certain times where the image resizing is completely ignored and the image gets loaded as it's normal size.

Can anyone see why the image sizing get's ignored in some instance?

Thanks for any help,
Clem
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

you need to call your resize function inside the onComplete listener.

The problem is that flash doesn't know the actual size of the image until after the image has downloaded completely (no idea why, this puzzles me too). It works 98% of the time because the images are usually loading quickly enough to get that data before you call the function.

As an alternative you could put the image dimensions in the xml file and then do the resize based on that instead of waiting for the load to complete.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.