【问题标题】:Actionscript problem in Dynamic TextField动态文本字段中的 Actionscript 问题
【发布时间】:2011-05-31 12:50:45
【问题描述】:

可以在flash as3的动态textField中做一个单词作为按钮吗?

【问题讨论】:

  • 如果有,你会接受答案吗?
  • 别忘了标记正确答案!
  • Benny,您在浪费人们的时间并让网站看起来像是您发布的 5 个问题没有合适的答案。我们都从自己的个人生活中抽出时间来帮助人们,而我们所要求的回报是,您从生活中抽出 1.23480473 秒,将鼠标移到接受按钮上并单击它。请停止您的单向参与,否则人们几乎会忽略您。
  • @Taurayi :非常抱歉迟到了。我还没有得到答案。

标签: flash actionscript-3 flash-cs3


【解决方案1】:

实际上与此问题的其他答案相反,您可以(有点)。通过在Textfield 对象的htmlText 属性的字符串值中使用图像标记,您可以使用库中的显示对象作为其源。然后您可以使用Textfield 对象的getImageReference() 方法从库中获取以显示对象为源的图像标签。举个例子:

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.events.MouseEvent;

    public class Main extends Sprite 
    {
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);

        }// end function

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            var textField:TextField = new TextField()
            textField.width = 125;
            textField.height = 50;
            textField.htmlText = "This is a button <img id='myButton' src='MyButton'/> ";
            addChild(textField);

            var myButton:Sprite = textField.getImageReference("myButton") as Sprite;
            myButton.addEventListener(MouseEvent.CLICK, onMyButtonClick);

        }// end function

        private function onMyButtonClick(e:MouseEvent):void
        {
            trace("CLICKED!!!");

        }// end function

    }// end class

}// end package

【讨论】:

  • 尽管我知道 Benny Geo 不会接受任何给出的答案,但希望有人会觉得这很有用。
  • 做得很好。 html 总是有点不稳定,但 +1 可以正常工作
  • @locrizak 我同意,这就是为什么我说“你可以(有点)”。我确实认为可以使用文本布局框架来实现文本字段中的按钮,但是我又不确定,因为我对此了解不多。
  • @Taurayi 是的,我听到了。。一年多没做过 flash(动作脚本),但仍然记得大部分。
  • @Taurayi:如果我找到了,我会在这里更新。感谢您的友好回复。
【解决方案2】:
【解决方案3】:

TextField 中没有 addChild 方法。但是您可以作弊并将按钮放在 TextField 上(即将其添加到 TextField 的容器中)。

【讨论】:

    【解决方案4】:

    简短的回答,不。您需要创建一个包含按钮和文本字段的包装类/MovieClip。

    【讨论】:

    • 我需要一个特定的单词作为按钮。
    • 在 SimpleButton/UIButton 上(抱歉忘记了课程)?
    • UIButton!!!我不知道...我想动态地将单词分配为按钮。
    猜你喜欢
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多