Lavorando per un player mp3 per un cliente, e vedendo la similarità tra il caricamento dei suoni e quello dei movieclip, ho deciso di creare una classe.
/**
* Creates a visual representation of a percentage
*
* @author Michael Avila
* @version 1.0.5
*/
class PBar
{
private static var count:Number = 0;
private var id:Number;
private var bar:MovieClip;
private var back:MovieClip;
private var fill:MovieClip;
private var outline:MovieClip;
private var fill_color:Number = 0xFF0000;
private var back_color:Number = 0xCCCCCC;
private var outline_color:Number = 0x0;
private var width:Number = 100;
private var height:Number = 10;
private var percent:Number = 0;
private var target:MovieClip;
/**
* Constructor
*
* @target The movieclip the PBar will be created into.
* ...
* @width The width of the PBar
* ...
* @height The height of the PBar
*/
public function PBar( target:MovieClip, width:Number, height:Number )
{
if ( target == undefined )
{
throw new Error("Required Parameter target for object PBar");
}
else
{
this.target = target;
}
if ( height != undefined)
{
this.width = width;
this.height = height;
}
draw();
id = PBar.count++;
}
/**
* Sets the percent for this progress bar to display.
*
* @percent The Percentage to display
*/
public function setPercent( percent:Number ):Void
{
percent = Math.max( percent, 0 );
percent = Math.min( percent, 100 );
this.percent = percent;
fill._width = width * (percent/100);
}
/**
* Returns the percent this PBar currently represents.
*/
public function getPercent() : Number
{
return percent;
}
/**
* Sets the x, y position of this PBar.
*/
public function setPosition( x:Number, y:Number ):Void
{
bar._x = x;
bar._y = y;
}
/**
* Sets the fillColor, outlineColor and backColor for this PBar
*/
public function setStyle( fillColor:Number, outlineColor:Number, backColor:Number ) : Void
{
if (arguments.length == 3)
{
fill_color = fillColor;
outline_color = outlineColor;
back_color = backColor;
draw();
}
}
private function draw():Void
{
if (bar == undefined)
{
bar = target.createEmptyMovieClip("pbar" + id, target.getNextHighestDepth());
back = bar.createEmptyMovieClip("back", 0);
fill = bar.createEmptyMovieClip("fill", 1);
outline = bar.createEmptyMovieClip("outline", 2);
}
var percentWidth:Number = Math.max(width * (percent/100), 1);
fill.beginFill(fill_color);
fill.lineTo(0, height);
fill.lineTo(1, height);
fill.lineTo(1, 0);
fill.lineTo(0, 0);
fill.endFill();
fill._width = percentWidth;
back.beginFill(back_color);
back.lineTo(0, height);
back.lineTo(width, height);
back.lineTo(width, 0);
back.lineTo(0, 0);
back.endFill();
outline.lineStyle( 0, outline_color, 100 );
outline.lineTo(0, height);
outline.lineTo(width, height);
outline.lineTo(width, 0);
outline.lineTo(0, 0);
}
}
Continua a leggere su http://www.createage.com/blog/?p=73


























