开发者

in Flash Builder 4.5, is there any fixable reason why Design view isn't correctly visualizing a simple Label?

开发者 https://www.devze.com 2023-03-28 01:57 出处:网络
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\".

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" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号