Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    Ridimensionamento immagini

    Ciao a tutti!
    Avrei il seguente problema:
    la parte di codice che è riportata di seguito carica delle immagini di dimensione arbitraria e le adatta al box "container_mc"; il problema è che non riesco a centrare perfettamente tutte le immagini... Qualcuno ha idea di come si possa fare? Preciso che il codice proviene dal libro "Object Programming with ActionScript" che non possiedo... Grazie per i vostri consigli! Bye!


    //Attesa per il caricamento dell'immagine; ridimensionamento
    //e conteggio per il successivo caricamento
    SlideShowClass.prototype.waitForLoadedImage = function()
    { if(this.container_mc.getBytesLoaded() > 4 && this.container_mc.getBytesLoaded() == this.container_mc.getBytesTotal())
    { clearInterval(this.loadCompleteID);
    //this.loadNextID = setInterval(this, "loadNextImage", this.interval_param * 1000);

    //Scala originale
    this.container_mc._xscale = this.container_mc._yscale = 100;

    // Controllo per le immagini oversized
    if(this.container_mc._width > this.origWidth ||
    this.container_mc._width > this.origHeight)
    {
    var wRatio = this.origWidth / this.container_mc._width;
    var hRatio = this.origHeight / this.container_mc._height;

    //Controllo se l'immagine è troppo larga o troppo alta
    if(wRatio < hRatio)
    {
    //too wide, shrink to fit width
    this.container_mc._width *= wRatio;
    //trace("Dimensione attuale dell'immagine:" + this.container_mc._width);
    //trace("Dimensione della box originale:" + this.origWidth);
    this.container_mc._height *= wRatio;
    this.container_mc._x = ((this.origWidth - this.container_mc._width)/2);
    //trace(this.container_mc._x);
    //this.container_mc._x = 100;
    } else
    {
    //too wide, shrink to fit height
    this.container_mc._width *= hRatio;
    //trace("Dimensione attuale dell'immagine:" + this.container_mc._width);
    //trace("Dimensione della box originale:" + this.origWidth);
    this.container_mc._height *= hRatio;
    this.container_mc._x = ((this.origWidth - this.container_mc._width)/2);
    //trace(this.container_mc._x);
    //this.container_mc._x = 100;
    } // if-else
    } // if oversized
    } // if loaded
    } // waitForLoadedImage

  2. #2
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Cioè cosa succede?

  3. #3
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Ho visto. Modifica lo script così:

    codice:
    #initclip
    
    // Component Parameters
    
    
    //Constructor
    function SlideShowClass()
    {	this.init();
    }
    SlideShowClass.prototype = new MovieClip();
    
    //Initialize the component
    SlideShowClass.prototype.init = function()
    {
    	this.panel_mc._visible = this.showPanel_param;
    	var panel_color = new Color(this.panel_mc);
    	panel_color.setRGB(this.panelColor_param);
    	this.label_txt._visible = this.showTitle_param;
    	
    	//Remember original container width and height
    	this.origWidth = this.container_mc._width;
    	this.origHeight = this.container_mc._height;
    	this.center = this.container_mc._x + (this.origWidth / 2);
    	
    	//Current pointer to a position in the arrays
    	this.imagePointer = 0;
    	
    	//Load the first image
    	this.loadNextImage();
    } // init
    
    //Load the next image into the container movieclip
    SlideShowClass.prototype.loadNextImage = function()
    {
    	this.container_mc._alpha = 0;
    	this.container_mc.loadMovie(this.directoryPath_param + 
    					this.fileNames_param[this.imagePointer]);
    	this.label_txt.text = this.imageTitles_param[this.imagePointer];
    	
    	//Wait for image to load before counting down to next image
    	clearInterval(this.loadNextID);
    	this.loadCompleteID = setInterval(this, "waitForLoadedImage", 100);
    
    	this.imagePointer ++;
    	if(this.imagePointer >= this.fileNames_param.length)
    		this.imagePointer = 0;
    }
    
    //Wait for image to load completely before resizing and 
    //counting down to the next load.
    SlideShowClass.prototype.waitForLoadedImage = function()
    {	if(this.container_mc.getBytesLoaded() > 4 && this.container_mc.getBytesLoaded() == this.container_mc.getBytesTotal())
    	{	clearInterval(this.loadCompleteID);
    		this.loadNextID = setInterval(this, "loadNextImage", this.interval_param * 1000);
    		
    		//Reset to original scale
    		this.container_mc._xscale = this.container_mc._yscale = 100;
    
    		// Test for over-sized image
    		if(this.container_mc._width > this.origWidth ||
    		   this.container_mc._width > this.origHeight)
    		{
    			// Test for displayMode_param
    			if(this.displayMode_param == "Maintain Aspect Ratio")
    			{
    				var wRatio = this.origWidth / this.container_mc._width;
    				var hRatio = this.origHeight / this.container_mc._height;
    				
    				//Test if it's too wide or too tall
    				if(wRatio < hRatio)
    				{
    					//too wide, shrink to fit width
    					this.container_mc._width *= wRatio;
    					this.container_mc._height *= wRatio;
    				} else
    				{
    					//too wide, shrink to fit height
    					this.container_mc._width *= hRatio;
    					this.container_mc._height *= hRatio;
    				} // if-else wider or taller
    			} else
    			{
    				// Exact Fit
    				this.container_mc._width = this.origWidth;
    				this.container_mc._height = this.origHeight;
    			} // if-else Maintain Aspect Ratio or Exact Fit
    		} // if oversized
    		this.container_mc._x = this.center - (this.container_mc._width / 2)
    		this.container_mc._alpha = 100;
    	} // if loaded
    } // waitForLoadedImage
    
    Object.registerClass("FSlideShowSymbol", SlideShowClass);
    
    #endinitclip

  4. #4
    Grazie mille NegaTyve! Un ulteriore domandina; ora le immagini si centrano perfettamente; il problema è che rimane uno sfarfallio dovuto al caricamento dell'immagine e scuccessivo ridimensionamento. Hai idea di come si possa togliere questo flickering? grazie!

  5. #5
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Ho rimodificato lo script sopra, per non occupare troppo spazio: adesso comprende anche quest'ultimo accorgimento.

  6. #6
    Grazie veramente! Sei un pozzo di San Patrizio di conoscenza! Spero di tendere asintoticamente alla tua abilità e conoscenza. Bye.

  7. #7
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    eh, addirittura..

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.