开发者

AS3 - Creating Text Field in White Board

开发者 https://www.devze.com 2023-04-05 11:53 出处:网络
I have to create a white board in Flash Action Script 3.. I\'m unable to create the text box property in the white box. When i open the swf i need a text box property with whch i can create a text box

I have to create a white board in Flash Action Script 3.. I'm unable to create the text box property in the white box. When i open the swf i need a text box property with whch i can create a text box f开发者_JS百科ield where ever the user wishes. Please help..


Something like this?


Whiteboard.as

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

    public class Whiteboard extends Sprite
    {

        private var _whiteboard : Sprite;
        private var _currentText : TextBox;

        public function Whiteboard()
        {
            super();

            createWhiteboard();

            enableUserInput();
        }

        private function createWhiteboard() : void
        {
            // create whiteboard sprite
            _whiteboard = new Sprite();

            // add to displaylist
            addChild(_whiteboard);

            // draw graphics
            with(_whiteboard.graphics)
            {
                lineStyle(10, 0x666666, 1);
                beginFill(0xFFFFFF, 1);
                drawRect(0, 0, 800, 600);
                endFill();
            }
        }

        private function enableUserInput() : void
        {
            _whiteboard.addEventListener(MouseEvent.CLICK, onUserInteract);
        }

        private function onUserInteract(event : MouseEvent) : void
        {
            // remove if empty
            if(_currentText && _currentText.htmlText.length == 0)
            {
                // remove from displaylist
                _whiteboard.removeChild(_currentText);
            }

            // add new
            if(event.target == _whiteboard)
            {
                _currentText = new TextBox();
                _currentText.x = event.stageX;
                _currentText.y = event.stageY;

                // add to displaylist
                _whiteboard.addChild(_currentText);
            }
            else
            {
                // use clicked text
                _currentText = event.target as TextBox;
            }

            // set selection
            _currentText.setSelection(0, _currentText.htmlText.length);

            // set focus
            stage.focus = _currentText;
        }

    }

}

import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;

class TextBox extends TextField
{
    function TextBox()
    {
        super();

        background = true;
        backgroundColor = 0xFF88FF;
        multiline = false;
        autoSize = TextFieldAutoSize.LEFT;
        type = TextFieldType.INPUT;
        htmlText = "";
        selectable = true;
        defaultTextFormat = new TextFormat("_sans", 18, 0xFFFFFF);

    }
}

AS3 - Creating Text Field in White Board

0

精彩评论

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

关注公众号