[flexcoders] Re: Repeating background for a component

2009-11-16 Thread valdhor
I have used http://renaun.com/blog/2006/12/08/165/ successfully.

--- In flexcoders@yahoogroups.com, Wally Kolcz wko...@... wrote:

 Does anyone know, or have a link to an example, for a tutorial on how to 
 repeat a background for a component? I want to apply a repeating texture to 
 either a Canvas or VBox but cannot seem to find a good working example. Found 
 a ton that work for the Application. Thanks!





[flexcoders] Re: Repeating background for a component

2009-11-16 Thread jamesfin



var repeat:RepeatBackground = new RepeatBackground();
addChild(repeat);
repeat.percentHeight = 100;
repeat.percentWidth = 100;




package
{
import mx.containers.Canvas;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Loader;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.geom.Matrix;
import flash.net.URLRequest;
import flash.display.Sprite;

import mx.controls.Image;
import mx.core.BitmapAsset;
import mx.graphics.RectangularDropShadow;
import mx.skins.RectangularBorder;
import mx.core.Application;
import mx.core.UIComponent;

public class RepeatBackground extends Canvas
{
public function RepeatBackground()
{
super();
}

private var tile:BitmapData;

[Embed(source='assets/main_bg.png')]
private var imgCls:Class;

override protected function updateDisplayList(unscaledWidth:Number, 
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);

if( this.parent != null ) {
if( imgCls == null ) {
var backgroundImage:Object = UIComponent( this.parent 
).getStyle( backgroundImage );
if( backgroundImage != null  backgroundImage !=  ) {
imgCls = Class( backgroundImage );
(this.parent as UIComponent).setStyle( 
backgroundImage,  );
}
}
if( imgCls != null ) {
try {
var background:BitmapAsset = BitmapAsset(new imgCls());
tile = background.bitmapData;

var transform: Matrix = new Matrix();

alpha = .5;
graphics.clear();
graphics.beginBitmapFill(tile, transform, true, true);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
} catch( e:TypeError ) {
// Throw an custom error if imgCls is not a valid type
throw new Error( backgroundImage value is not a valid 
image class );
} finally {
;// Catch all just ignore
}
}
}
}


}
}



--- In flexcoders@yahoogroups.com, Wally Kolcz wko...@... wrote:

 Does anyone know, or have a link to an example, for a tutorial on how to 
 repeat a background for a component? I want to apply a repeating texture to 
 either a Canvas or VBox but cannot seem to find a good working example. Found 
 a ton that work for the Application. Thanks!