创建具有 Label 组件的应用程序

以下过程解释了如何在创作时将 Label 组件添加到应用程序。在此示例中,标签仅显示文本"Expiration Date"。

创建具有 Label 组件的应用程序:

  1. 创建一个新的 Flash 文件 (ActionScript 3.0) 文档。
  2. 将一个 Label 组件从"组件"面板拖到舞台上,并在"属性"检查器中为该组件输入以下值:
    • 输入 aLabel 作为实例名称。
    • 输入 80 作为 W 值。
    • 输入 100 作为 X 值。
    • 输入 100 作为 Y 值。
    • 输入 Expiration Date 作为 text 参数。
  3. 将一个 TextArea 组件拖到舞台上,并在"属性"检查器中为该组件输入以下值:
    • 输入 aTa 作为实例名称。
    • 输入 22 作为 H 值。
    • 输入 200 作为 X 值。
    • 输入 100 作为 Y 值。
  4. 打开"动作"面板,在主时间轴中选择第 1 帧,然后输入以下 ActionScript 代码:
    var today:Date = new Date();
    var expDate:Date = addDays(today, 14);
    aTa.text = expDate.toDateString();
    
    function addDays(date:Date, days:Number):Date {
        return addHours(date, days*24);
    }
    
    function addHours(date:Date, hrs:Number):Date {
        return addMinutes(date, hrs*60);
    }
    
    function addMinutes(date:Date, mins:Number):Date {
        return addSeconds(date, mins*60);
    }
    
    function addSeconds(date:Date, secs:Number):Date {
            var mSecs:Number = secs * 1000;
            var sum:Number = mSecs + date.getTime();
            return new Date(sum);
    }
    
  5. 选择"控制">"测试影片"。

以下示例使用 ActionScript 创建一个 Label 组件。该示例使用 Label 来标识 ColorPicker 组件的功能,并使用 htmlText 属性将格式应用于 Label 的文本。

使用 ActionScript 创建 Label 组件实例:

  1. 创建一个新的 Flash 文件 (ActionScript 3.0) 文档。
  2. 将一个 Label 组件从"组件"面板拖到当前文档的"库"面板中。
  3. 将一个 ColorPicker 组件从"组件"面板拖到当前文档的"库"面板中。
  4. 打开"动作"面板,在主时间轴中选择第 1 帧,然后输入以下 ActionScript 代码:
    import fl.controls.Label;
    import fl.controls.ColorPicker;
    
    var aLabel:Label = new Label();
    var aCp:ColorPicker = new ColorPicker();
    
    addChild(aLabel);
    addChild(aCp);
    
    aLabel.htmlText = '<font face="Arial" color="#FF0000" size="14">Fill:</font>';
    aLabel.x = 200;
    aLabel.y = 150;
    aLabel.width = 25;
    aLabel.height = 22;
    
    aCp.x = 230;
    aCp.y = 150;
    
  5. 选择"控制">"测试影片"。