Genero un clip y lo pinto con beginGradientFil, luego como quiero que cambie de color el degradado cuando pulse un boton, he recogido un codigo de internet que genera rgb a exadeimales, el problema viene que cuando redimensiono pantalla el color se pierde hasta que no le de otra vez al boton. Os pongo el codigo:
Código ActionScript:
Ver original
////////////////// import mx.transitions.Tween; import mx.transitions.easing.*; Stage.scaleMode = "noScale"; Stage.align = "TL"; /////// variables a = Stage.width; b = Stage.height; /////////////////// var miListener:Object = new Object(); creafons(); //////////////// function creafons(Fondo:MovieClip, angle:Number, from:Number, to:Number) { Fondo.firstColor = from; Fondo.secondColor = to; createEmptyMovieClip("Fondo",1); import flash.geom.*; var fillType:String = "linear"; var angle:Number = angle || 90; var colors:Array = [from, to]; var alphas:Array = [50, 50]; var ratios:Array = [127, 255]; var matrix:Matrix = new Matrix(); matrix.createGradientBox(a,a,0,0,0); var spreadMethod:String = "pad"; Fondo.beginGradientFill(fillType,colors,alphas,ratios,matrix,spreadMethod); Fondo.lineTo(0,25); Fondo.lineTo(0,b); Fondo.lineTo(a,b); Fondo.lineTo(a,0); Fondo.endFill(); } ///////////////////// function tweenGradientFondo(what:MovieClip, c1:Number, c2:Number, time:Number) { what.percent.stop; delete what.percent; var holder:Object = new Object(); holder.percent = 0; ///first color/// var red:Number = what.firstColor >>> (4*4) & 0xFF; var green:Number = what.firstColor >>> (2*4) & 0xFF; var blue:Number = what.firstColor >>> (0*4) & 0xFF; var toRed:Number = c1 >>> (4*4) & 0xFF; var toGreen:Number = c1 >>> (2*4) & 0xFF; var toBlue:Number = c1 >>> (0*4) & 0xFF; var redDiff:Number = (toRed-red)/100; var greenDiff:Number = (toGreen-green)/100; var blueDiff:Number = (toBlue-blue)/100; ///second color/// var red2:Number = what.secondColor >>> (4*4) & 0xFF; var green2:Number = what.secondColor >>> (2*4) & 0xFF; var blue2:Number = what.secondColor >>> (0*4) & 0xFF; var toRed2:Number = c2 >>> (4*4) & 0xFF; var toGreen2:Number = c2 >>> (2*4) & 0xFF; var toBlue2:Number = c2 >>> (0*4) & 0xFF; var redDiff2:Number = (toRed2-red2)/100; var greenDiff2:Number = (toGreen2-green2)/100; var blueDiff2:Number = (toBlue2-blue2)/100; what.percent = new Tween(holder, "percent", None.easeNone, 0, 100, time, true); what.percent.onMotionChanged = function() { ///FIRST COLOR/// var r = red+(redDiff*holder.percent); var g = green+(greenDiff*holder.percent); var b = blue+(blueDiff*holder.percent); what.firstColor = (r << (4*4)) | (g << (2*4)) | (b << (0*4)); /// ///SECOND COLOR/// var r2 = red2+(redDiff2*holder.percent); var g2 = green2+(greenDiff2*holder.percent); var b2 = blue2+(blueDiff2*holder.percent); what.secondColor = (r2 << (4*4)) | (g2 << (2*4)) | (b2 << (0*4)); ////set new gradient creafons(what,90,what.firstColor,what.secondColor); }; } ///////////////////// Stage.addListener(miListener); miListener.onResize = function() { a = Stage.width; b = Stage.height; creafons(); }; /////////////////// boto.onPress =function() { tweenGradientFondo(Fondo,0xffffff*Math.random(),0xffffff*Math.random(),1); }
No se porque se pierde la información de la variable, a ver si alguien me puede hechar un cable, gracias.