in Flash Builder 4.5, is there any fixable reason why Design view isn't correctly visualizing a simple Label?
Question: I tried the very simple code below based on an instructional code snippet, where I create a Label called "headline" with MXML, but use Actionscript to set headline.text = "ABC".
When I use the browser, I see the desired result of the Actionscript - the page displays the text "ABC". But when I use the Design view, it simply shows a blank/white square in that place.
I want to post a screenshot but this is my 1st day on this site, and I don't have the necessary 10 reputation yet.
The relevant code excerpt:
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected functi开发者_如何学Con application1_creationCompleteHandler(event:FlexEvent):void
{
headline.text="ABC";
}
]]>
</fx:Script>
<s:Label id="headline" fontSize="36" x="10" y="10" color="#FFFFFF" />
Answer:
Because creationCompleteHandler is an event that is set to be completed only upon REAL execution/loading of the application, the code inside that function was running properly in the browser (where the application would be REALLY executed), and not in Design view (where it would be pseudo-executed)
Why not set the text directly in the label:
<s:Label id="headline" fontSize="36" x="10" y="10" color="#FFFFFF" text="ABC" />
Or use binding:
<fx:Script>
<![CDATA[
[Bindable] public var headlineText:String = "ABC";
]]>
</fx:Script>
<s:Label text="{headlineText}" id="headline" fontSize="36" x="10" y="10" color="#FFFFFF" />
精彩评论