Actionscript problem in Dynamic TextField

后端 未结 4 1970
轮回少年
轮回少年 2021-01-17 05:18

Is possible to make a word as button within the dynamic textField in flash as3?

4条回答
  •  孤街浪徒
    2021-01-17 06:03

    Actually contrary to the other answers for this question, you can(kind of). By using an image tag in a string value for a Textfield object's htmlText property you can use a display object in the library as its source. Then you can use the Textfield object's getImageReference() method to get the image tag which has the display object from the library as its source. Heres an example:

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

    enter image description here

提交回复
热议问题