views:

1181

answers:

4

In my MXML file, I have a tab navigator with three vboxes.

<mx:TabNavigator width="624" height="100%">
        <mx:VBox label="Currents Quote" 
            width="100%">            
        </mx:VBox>
        <mx:VBox label="Quote Comparison" 
            width="100%">               
        </mx:VBox>
        <mx:VBox label="Reports" 
            width="100%">            
        </mx:VBox>      
</mx:TabNavigator>

Inside the VBox "Current Quote", I want a circle to be drawn. How can I achieve it?

A: 

Take a look at Degrafa.

mkurek
A: 

So in Flex this is a possibility:

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
this.addChild(mySprite);

That should work :)

ninumedia
+2  A: 

There's no MXML circle defined, so you have to create a circle control yourself and you can then include it in your MXML.

package mypackage
{
    class MyCircle extends UIComponent
    {
        public var x:int;
        public var y:int;
        public var radius:int;

        override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            graphics.drawCircle(x, y, radius);
        }
    }
}

then in your MXML you can use your custom control if you declare a namespace to refer to it at the top of your containing control...

<mx:VBox label="Currents Quote" width="100%">
    <mycontrols:MyCircle x=30 y=30 radius=30/>
</mx:VBox>

Code above was typed into the StackOverflow editor, so check it works!

There's a lot of help on the web for extending UIComponent and Sprite. The Adobe docs are pretty comprehensive.

EDIT: Include your controls as a namespace in the enclosing control or application

<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:mycontrols="mypackage.*" >
<mx:Script>

HTH

Simon
Is the Circle control to be created as an .as file?
Angeline Aarthi
yes, as a separate class in its own file
Simon
If I create as an .as file, It is not being included as a component with a name space??
Angeline Aarthi
If you are using FlexBuilder then create an ActionScript class in a source folder in your project. Then it will be visible to the IDE in code completion or in the design editor. If you include the custom control in your MXML file the IDE will automatically add a default namespace for you. If you are doing this all manually, then you need to give the class a package name and refer to that package in the namespace declarations at the top your MXML file. I'll add a declaration syntax to my answer.
Simon
it shows an error `1071: Syntax error: expected a definition keyword (such as function) after attribute public, not x.` in the line `public x:int;`
Angeline Aarthi
Can you tell what's wrong? My code is not correct above (I did include a disclaimer and I flip between Java and AS3 so I am prone to get it wrong when typing code in here). I'll correct it, but you really ought to know how to do that yourself, it is the very basics of the language construct.
Simon
I have corrected the errors,the method signature in the function didnt match,and needed to add var for the variables. Also have to add line style to make the circle visible. `graphics.lineStyle(1, 0x000000);` Thanks for ur help :-)
Angeline Aarthi
Also can u guide me in how to divide the circle into sectors? I need the circle that is created to be divided to 6 sectors.
Angeline Aarthi
Do you really want a pie chart?
Simon
Like a pie chart, but not that.. I need to load images n values into the separate sectors of this wheel like structure.. enabling Drag n drop is also required, but I don't know till what extent it is possible. Can u tell me if its possible?
Angeline Aarthi
see my second answer.
Simon
A: 

Embellishing for drag and drop etc...

Yes, pretty much anything is possible. If you don't want to use a pie chart (which I recommend you look at because it might make a lot of the drawing code very simple) then you need to embellish the MyCircle class above to trap the mouseDown event and to enable dragging from it using a DragSource object.

package mypackage
{
    class MyCircle extends UIComponent
    {
        ...snip...

        // to initiate a drag from this object
        private function MouseDown(e:MouseEvent):void
        {
            var ds:DragSource = new DragSource();
            if (data)
            {
                 // I'm adding the object's data to it, but you need to decide what you want in here
                ds.addData(data, "MyDragAction");
                mx.managers.DragManager.doDrag(this, ds, e);
            }
        }

        // to handle a drop
        private function HandleDrop(e:DragEvent):void
        {
            mx.managers.DragManager.acceptDragDrop(e.currentTarget);
            // you can get at whatever you put in the drag event here
        }
    }
}

You'll need to set these functions (and whichever else you wind up supporting for drag/drop) as event listeners on this object. You can do that in the object's constructor, you just have to make sure you are listening for the right event.

You have some digging to do, and the adobe docs are your friend, but it is all perfectly possible. As you add more to MyCircle you will get greater benefit from having it factored out into a separate control.

Simon