Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Movie clip resize not working when image is loaded

Status
Not open for further replies.

clemcrock

Programmer
Dec 17, 2006
63
US
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:
_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');


The load_movie_and_stop function is as follows:
Code:
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___

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:
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);

};

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

 
so far it's happening only when I'm testing online
 
Found the solution that worked (used ._xscale and ._yscale instead of ._width and ._height


Code:
function resize_movie_clip(clip_loader_name:MovieClip, max_width:Number, max_height:Number, center_offset:Number )
{
	if( (clip_loader_name._width > max_width) || ( clip_loader_name._height > max_height ) ) // If either dimension is too big...
    {
		 if( clip_loader_name._width > max_width )
		 {
			 _root.picsPage_mc.txt_test = "func if 1";
			  clip_loader_name._width = max_width;
			  clip_loader_name._yscale = clip_loader_name._xscale;
		  }
		  if( clip_loader_name._height > max_height )
		  {
			  _root.picsPage_mc.txt_test = "func if 2";
			  clip_loader_name._height = max_height;
			  clip_loader_name._xscale = clip_loader_name._yscale;
          }
	  }
      else { new_width = orig_width; new_height = orig_height;  }
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top