PDA

View Full Version : Any one know how to do drawing in actionscript?


john100
03-25-2006, 11:34 AM
Here the code, it cause error because it try to convert graphics to UI Component


<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initApp()" backgroundAlpha="0">

<mx:Script>
import flash.display.*;
import mx.controls.listClasses.*;
import mx.collections.*;
import mx.controls.*;
import com.graphics.*;

private function initApp():void
{
var circle:Shape = new Shape()
var xPos:Number = 100;
var yPos:Number = 100;
var radius:Number = 50;
circle.graphics.beginFill(0xFF8800);
circle.graphics.drawCircle(xPos, yPos, radius);
this.addChild(circle);
}
</mx:Script>
<mx:Canvas id="cvs" width="200" height="200">
</mx:Canvas>

</mx:Application>

hangalot
03-25-2006, 04:34 PM
there are two sollutions to this problem, and it depends on what you want which one will work for you.



var circle:UIObject = new UIObject();


or


this.allChildrenList.addChild(circle);


so the difference between the two is that in the first case flex will manage all the resizing and the rest of your item for you in the application, in the second case you are bypassing flex and just adding it to the display list directly

john100
03-25-2006, 10:54 PM
Thanks it work.
There is a slightly change. Instead of UIObject. Need to use UIComponent

var circle:UIComponent = new UIComponent();


<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initApp()" backgroundAlpha="0">

<mx:Script>
import flash.display.*;
import mx.controls.listClasses.*;
import mx.collections.*;
import mx.controls.*;
import com.graphics.*;

private function initApp():void
{
var circle:UIComponent = new UIComponent();
var xPos:Number = 100;
var yPos:Number = 100;
var radius:Number = 50;
circle.graphics.beginFill(0xFF8800);
circle.graphics.drawCircle(xPos, yPos, radius);
this.addChild(circle)
}
</mx:Script>
<mx:Canvas id="cvs" width="200" height="200">
</mx:Canvas>

</mx:Application>