Flex 4 creating new elements pragmatically.

33 views
Skip to first unread message

Craig McLeod

unread,
Aug 30, 2011, 9:45:41 AM8/30/11
to Flex ObjectHandles
Hi,

I am trying to use ObjectHandles and Flex 4 to create a dynamic canvas
for users to draw items.

I am using the following:

public function AddItemToCanvas():void{

var NewDashItem:DashBoardReportItem = new DashBoardReportItem();
NewDashItem.id = "flexShape4";

NewDashItem.model.ReportTemplateID = '26'
NewDashItem.model.x = 20;
NewDashItem.model.y = 1;
NewDashItem.model.width = 300;
NewDashItem.model.height = 200;
NewDashItem.model.CanvasItemID = 'flexShape4'


mainGroup.addElement(NewDashItem);
NewDashItem.id = "flexShape4";
NewDashItem.x=20;
NewDashItem.y=20;
NewDashItem.width = 300;
NewDashItem.height = 200;


var NewFlexModel:SimpleDataModel = new SimpleDataModel();

NewFlexModel.x = 20;
NewFlexModel.y = 1;
NewFlexModel.width = 300;
NewFlexModel.height = 200;
NewFlexModel.ReportTemplateID = '26'
NewFlexModel.CanvasItemID = 'flexShape4'
objectHandles.registerComponent( NewFlexModel, NewDashItem,
HandleDefinitions.NO_ROTATE_DEFINITION );




}

It almost works except the object handles are not attached to the
object.

can anyone advise?

Please and Thank you
Craig

Craig McLeod

unread,
Aug 30, 2011, 9:53:11 AM8/30/11
to Flex ObjectHandles
Hi,

I solved it by adding the line:

NewDashItem.model = NewFlexModel;

Tharage Ntakadzeni

unread,
Aug 30, 2011, 9:55:57 AM8/30/11
to object...@googlegroups.com
Hi,

I am trying to use ObjectHandles and Flex 4 to create a dynamic canvas,images,text
for users to resize items.

I have a problem when i set top,bottom,left,right on the components ,its breaks the handlers. does anyone have the solution

--
Kind regards,
Tharage Ntakadzeni
Software Developer
0822625862



Craig McLeod

unread,
Aug 31, 2011, 3:31:09 AM8/31/11
to Flex ObjectHandles
Hi,

Tharage, your phone number looks like its from SA ;)

Any how, for text make sure you are using the text component supplied
in the OH2 example not the standard one.
Also note they don't recommend using controls directly, so embed in
components rather. And use dynamic sizing.
That way the redraw works better.

and finally modify the SimpleDataModel.as with any extras you need
passed into your components and pass them in during instantiation.

The Flex4Example provided works perfectly, if you use my code above
you can see how to add something to a canvas.

The important part is the creation of a model and a control, the
adding of the control as an element to the canvas, and then the
linking of the control to its model, before you register it with
object handles.

Here is the final of my code:
NewDashItem.model = NewFlexModel;

objectHandles.registerComponent( NewFlexModel, NewDashItem,
HandleDefinitions.NO_ROTATE_DEFINITION );

}

Regards
Dr Craig McLeod
Senior Developer Sumit Solutions.

On Aug 30, 3:55 pm, Tharage Ntakadzeni <tntakadz...@gmail.com> wrote:
> Hi,
>
> I am trying to use ObjectHandles and Flex 4 to create a dynamic
> canvas,images,text
> for users to resize items.
>
> I have a problem when i set top,bottom,left,right on the components ,its
> breaks the handlers. does anyone have the solution
>
> --
> *Kind regards,
> Tharage Ntakadzeni
> Software Developer
> 0822625862*

Craig McLeod

unread,
Aug 31, 2011, 3:33:01 AM8/31/11
to Flex ObjectHandles
Also note:

I added:

ReportTemplateID
CanvasItemID

to the DataModel for my own application specific needs, because Im
keeping track of the state of objects on users canvases.

They dont exist in the standard ObjectHandles SimpleDataModel.
Reply all
Reply to author
Forward
0 new messages