Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Constraint-based positioning of components using ActionScript 3.0

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
448

Hi there,

I am building a Flex3 and ActionScript application. I need to build much of the UI dynamically so I am using ActionScript for this.

My problem is that I can't figure out how use constraint-based positioning for my components.

Take for example this MXML that instantiates a TitleWindow.

<mx:TitleWindow layout="absolute" id="myid" title="My Window" left="10" right="10" top="10" bottom="10">
</mx:TitleWindow>

I can do the same thing in ActionScript...

var myTitleWindow:TitleWindow = new TitleWindow;
myTitleWindow.id = "myid";
myTitleWindow.layout = "absolute";
myTitleWindow.title="My Window";
this.addChild(myTitleWindow);

...but I cannot figure out how to set the left, right, top bottom attributes. I have looked at the generated ActionScript from the MXML example and it uses the stylesFactory property of the mx.core.UIComponentDescriptor class but I can't figure out how to replicate this in my code.

As always I would appreciate anyones help with this.

Cheers

Graham Robbo

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
426

Hey Graham. Check this out.

var aComponent:yourComponent = new yourComponent();
var theStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
theStyle.setStyle(u201Dtopu201D, 0);
theStyle.setStyle(u201Dbottomu201D, 0);
theStyle.setStyle(u201Dleftu201D, 0);
theStyle.setStyle(u201Drightu201D, 0);
theStyle.setStyle(u201DhorizontalCenteru201D, 0); 
aComponent.styleDeclaration = theStyle;

Regards,

Rich Heilman

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
427

Hey Graham. Check this out.

var aComponent:yourComponent = new yourComponent();
var theStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
theStyle.setStyle(u201Dtopu201D, 0);
theStyle.setStyle(u201Dbottomu201D, 0);
theStyle.setStyle(u201Dleftu201D, 0);
theStyle.setStyle(u201Drightu201D, 0);
theStyle.setStyle(u201DhorizontalCenteru201D, 0); 
aComponent.styleDeclaration = theStyle;

Regards,

Rich Heilman

Read only

0 Likes
426

Thanks Rich - your response time is not bad either.

Cheers

Graham Robbo