//récupère l'image chargé var img:BitmapData = new Bitmap(image1Loader.content).bitmapData; //calcul de la nouvelle taille var ratio:Number = img.height / img.width; var newWidth:int; var newHeight:int; if (img.width > widthMAX) { newWidth = widthMAX; newHeight = int(newWidth * ratio); } if (newHeight > heightMax) { newHeight = heightMax; newWidth = int(newHeight / ratio); } //matrice pour redimentionner var m:Matrix = new Matrix(); m.scale(newWidth / img.width, newHeight / img.height); //dessine ton image image1_mc.graphics.beginBitmapFill(img, m); image1_mc.graphics.drawRoundRect(0, 0, newWidth, newHeight, 50, 50); image1_mc.graphics.endFill();
image1_mc.name = "picture"+nbTour; trace("CREE : " + image1_mc.name); image1_mc.z = nbTour; image1_mc.alpha = 0; mesImages1[nbTour]._mc = image1_mc; var image1Loader:Loader; function loadImage1(url:String):void { try { // Set properties on my Loader object image1Loader = new Loader(); image1Loader.load(new URLRequest(url)); image1Loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, image1Loading); image1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, image1Loaded); image1Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, image1Error); } catch(ex) { TXTError.text = "EXCEPTION loadImage1() " + ex.message; } } // fin loadImage1 function image1Loaded(e:Event):void { try { // Load Image image1_mc.addChild(image1Loader); trace("Load init (nbTour:" + nbTour + ")"); var lIndice:int = image1_mc.z; if(nbTour == lIndice) { reTailleIMG(image1_mc,lIndice); addChild(image1_mc); Tweener.addTween(image1_mc,{alpha:1, time:2, transition:"linear"}); var leMasque:Shape= new Shape(); leMasque.cacheAsBitmap=true; leMasque.graphics.beginFill(0xFFFFFF); leMasque.graphics.lineStyle(1); leMasque.graphics.drawRoundRect(0,0,image1_mc.width,image1_mc.height,50); leMasque.graphics.endFill(); image1_mc.cacheAsBitmap=true; image1_mc.mask=leMasque; leMasque.x=image1_mc.x; leMasque.y=image1_mc.y; } mesImages1[lIndice].isLoaded=true; } catch(ex) { TXTError.text = "EXCEPTION image1Loaded " + ex.message; } } // fin image1Loaded function image1Loading(e:ProgressEvent):void { // Use it to get current download progress // Hint: You could tie the values to a preloader :) } function image1Error(e:IOErrorEvent):void{ var leTxt:TextField = new TextField(); leTxt.text = "image1Error : Load Error !"; leTxt.textColor = 0xF3F3F3; leTxt.x=0; leTxt.y=0; leTxt.width=widthAnimation; leTxt.height=heightAnimation; addChild(leTxt); } //charge dans le clip loadImage1(mesImages1[nbTour]._path);
function reTailleIMG(leMovieClip:MovieClip,indice:Number) { try { var widthActu:Number = mesImages1[indice].widthIMG; var heightActu:Number = mesImages1[indice].heightIMG; trace("RETAILLE IMG " + indice + "-" + widthActu + "-" + heightActu ); var ratio = widthActu/heightActu; var newWidth:int=0; var newHeight:int=0; if(widthActu>heightActu) { newWidth = widthMAX; //widthActu; newHeight = newWidth/ratio; } else { newHeight = heightMAX; //heightActu; newWidth = ratio*newHeight; } if (newWidth > widthMAX) { newWidth = widthMAX; newHeight = (newWidth / ratio); if(newHeight > heightMAX) { newHeight = heightMAX; newWidth = (ratio * newHeight); } } if(newHeight > heightMAX) { newHeight = heightMAX; newWidth = (newHeight * ratio); if (newWidth > widthMAX) { newWidth = widthMAX; newWidth = (newWidth / ratio); } } leMovieClip.width = newWidth; leMovieClip.height = newHeight; leMovieClip.x = Math.round((widthAnimation-newWidth)/2); var sousBandeau:int = leBandeau.y+leBandeau.height+10; leMovieClip.y = sousBandeau + Math.round((heightAnimation - sousBandeau - newHeight)/2); } catch(ex) { TXTError.text = "EXCEPTION reTailleIMG " + ex.message; } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question