2

私はアクションスクリプトとして表現したいこのMXMLを持っています:

<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>

私はこれを試しましたが成功しませんでした:

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

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

css スタイルのテキストをアクション バー (複数のラベル) に追加するにはどうすればよいですか? また、コードを複製する必要がないように、他のビューにこのアクションバーを継承させることは可能ですか (すべてのビューには共通の要素があります)。

4

1 に答える 1

4

この構文:

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

これが存在するコンポーネントで titleContent プロパティを設定していることを意味します。プロパティと新しいクラス インスタンスの違いは、ケースからわかります。クラス名は常に大文字で始まります。一方、プロパティ名は小文字で始まります。これがプロパティであるクラスを指定しませんでした。しかし、あなたはモバイルを扱っているので、それはビューだと思います。titleContent プロパティは配列です。

そう; これを行う必要があります:

// 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);

これは、提供した MXML コードを ActionScript に変換する適切な方法です。あなた自身のコードが新しい ActionBar() を作成しようとしたので、これが本当にあなたが望んでいたものかどうかはわかりません。

于 2013-03-08T15:31:13.617 に答える