DominicM
DominicM

Reputation: 6898

ActionBar in pure Actionscript

I have this MXML that I would like to express as actionscript:

<s:titleContent>
    <s:Label text="Title" fontWeight="bold" fontSize="20" height="20" verticalAlign="top" />
    <s:Label text=".com" fontSize="12" height="17" verticalAlign="bottom" />
</s:titleContent>

I've tried this with no success:

var chrome:ActionBar = new ActionBar();
chromeTitle.text = "Title";

chrome.setStyle("fontSize", 20);
chrome.title = "Title";
chrome.title = chromeTitle;

How can I add css styled text to the action bar (multiple labels)? Also is it possible to make other views inherit this action bar so that I dont't have to duplicate code (all vies would have common elements)?

Upvotes: 2

Views: 501

Answers (1)

JeffryHouser
JeffryHouser

Reputation: 39408

This syntax:

<s:titleContent>
 ...
</s:titleContent>

Means that you are setting the titleContent property on the component that this resides under. You can tell the difference between properties and new class instances from the case. Class names always start with an uppercase; whereas property names start with a lowercase. You didn't specify which class this is a property on; but since you're dealing with mobile I assume it is a view. the titleContent property is an array.

So; you must do this:

// create the first label and set properties
var tempLabel :Label = new Label();
tempLabel.text = 'Title';
tempLabel.setStyle('fontWeight','bold');
tempLabel.setStyle('fontSize',20);
tempLabel.height = 20;
tempLabel.setStyle('verticalAlign','top');

// add label to titleContent array
this.titleContent.push(tempLabel);

// create next label
tempLabel :Label = new Label();
tempLabel.text = '.com';
tempLabel.setStyle('fontSize',12);
tempLabel.height = 17;
tempLabel.setStyle('verticalAlign','bottom');

// add second label to titleContent array
this.titleContent.push(tempLabel);

That is the proper way to convert the MXML code you provided into ActionScript. Since your own code tried to create a new ActionBar() I'm not sure what you if this is really what you wanted.

Upvotes: 4

Related Questions