From last 2 days I was working on the flex drawing objects. I tried with following example from flex help.
import flash.display.*;
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);

But there was a error pop up comes every-time -
“Type Coercion failed: cannot convert flash.display::Shape to mx.core.IUIComponent.”

Then I studied the sprite object, Sprite objects can act as display object containers and respond to mouse clicks. Then I tried flex help for sprite & I got this code -

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
var label:TextField = new TextField();
label.text = “hello”;
label.x = 20;
label.y = 20;
mySprite.addChild(label);
this.addChild(mySprite);

But it also gives meĀ  “Type Coercion failed: cannot convert flash.display::Sprite to mx.core.IUIComponent.” error.
Then I searched on google & I got this code. Works fine & I can draw any object at run-time.

var myUIComponent:UIComponent = new UIComponent();
myUIComponent.graphics.beginFill(0xFFCC00);
myUIComponent.graphics.drawCircle(30, 30, 30);
var label:Label = new Label();
label.text = “hello”;
label.x = 20;
label.y = 20;
myUIComponent.addChild(label);
this.addChild(myUIComponent);

Here is the link for this page in google -
http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001855.html

Thank you,

Purva

About these ads