Ganael, You need to be overriding the draw method. The createswatch method is only used in custom development like creating a legend.Here is some code from Mansour's Blog. http://thunderheadxpler.blogspot.com/package com.esri.overlay
{
import com.esri.ags.Map;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.symbol.Symbol;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.geom.Matrix;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.system.LoaderContext;
import mx.controls.Label;
public class OverlaySymbol extends Symbol
{
private const m_matrix:Matrix = new Matrix();
private var m_bitmap:Bitmap;
private var m_source:Object;
private var m_width:Number = 0;
private var m_height:Number = 0;
private var m_rotation:Number = 0;
private var m_iname:String = "";
private var m_alpha:Number = 1;
public function OverlaySymbol(source:String=null, width:Number=0,
height:Number=0, rotation:Number=0, alpha:Number=1)
{
m_source = source;
m_width = width;
m_height = height;
m_rotation = rotation;
m_alpha = alpha;
}
[Bindable]
public function get source():Object
{
return m_source;
}
public function set source(value:Object):void
{
if (value != m_source)
{
m_bitmap = null;
m_source = value;
dispatchEventChange();
}
}
[Bindable]
public function get rotation():Number
{
return m_rotation;
}
public function set rotation(value:Number):void
{
if (value != m_rotation)
{
m_rotation = value;
dispatchEventChange();
}
}
[Bindable]
public function get width():Number
{
return m_width;
}
public function set width(value:Number):void
{
if (value != m_width)
{
m_width = value;
dispatchEventChange();
}
}
[Bindable]
public function get height():Number
{
return m_height;
}
public function set height(value:Number):void
{
if (value != m_height)
{
m_height = value;
dispatchEventChange();
}
}
[Bindable]
public function get alpha():Number
{
return m_alpha;
}
public function set alpha(value:Number):void
{
if (value != m_alpha)
{
m_alpha = value;
dispatchEventChange();
}
}
override public function clear(sprite:Sprite):void
{
sprite.graphics.clear();
}
override public function draw(sprite:Sprite, geometry:Geometry, attributes:Object, map:Map):void
{
if (geometry is MapPoint)
{
drawOverlay(sprite, MapPoint(geometry), map);
}
}
private function drawOverlay(sprite:Sprite, mapPoint:MapPoint, map:Map):void
{
if (m_bitmap == null)
{
if (m_source is Class)
{
m_bitmap = new m_source();
drawBitmap(sprite, mapPoint, map);
}
else if (m_source is String)
{
var url : String = String(m_source);
if( Capabilities.isDebugger == true )
{
url = url + (url.indexOf("?") > -1 ? "&debug=true" : "?debug=true");
}
const loaderContext:LoaderContext = new LoaderContext();
loaderContext.checkPolicyFile = true;
const loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoaderError );
loader.load(new URLRequest(url), loaderContext);
function completeHandler(event:Event):void
{
const loaderInfo:LoaderInfo = event.target as LoaderInfo;
m_bitmap = loaderInfo.content as Bitmap;
drawBitmap(sprite, mapPoint, map);
}
function onLoaderError(evt:Event):void
{
//do nothing
}
}
}
else
{
drawBitmap(sprite, mapPoint, map);
}
}
private function drawBitmap(sprite:Sprite, mapPoint:MapPoint, map:Map):void
{
const width2:Number = m_width / 2.0;
const height2:Number = m_height / 2.0;
const xmin:Number = toScreenX(map, mapPoint.x);
const xmax:Number = toScreenX(map, mapPoint.x + m_width);
const ymax:Number = toScreenY(map, mapPoint.y);
const ymin:Number = toScreenY(map, mapPoint.y + m_height);
const width:Number = xmax - xmin;
const height:Number = ymax - ymin;
m_matrix.a = width / m_bitmap.bitmapData.width;
m_matrix.d = height / m_bitmap.bitmapData.height;
m_matrix.tx = width / m_bitmap.bitmapData.width;
m_matrix.ty = height / m_bitmap.bitmapData.height;
sprite.x = toScreenX(map, mapPoint.x);
sprite.y = toScreenY(map, mapPoint.y);
sprite.rotation = m_rotation;
sprite.alpha = m_alpha;
sprite.graphics.beginBitmapFill(m_bitmap.bitmapData, m_matrix, false, true);
sprite.graphics.drawRect(m_matrix.tx, m_matrix.ty, width, height);
sprite.graphics.endFill();
var tLabel:Label = new Label();
tLabel.text = m_iname;
tLabel.x = sprite.x + 10;
tLabel.y = sprite.y + 10;
sprite.addChild(tLabel);
}
}
}