0

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

0

4 Answers 4

4

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

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

nicely done. html is always a little wonky but +1 for it working
@locrizak i agree, thats why I said "you can(kind of)". I do think that a button in a textfield can be achieved using the Text Layout Framework, but then again I'm not sure since I don't know that much about it.
@Taurayi Yeah I hear ya.. Haven't done flash in over a year (actionscript that is) but still remember most of it.
@Taurayi: If I found, I will update here. Thanks for your kind response.
2
+50

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000552.html

http://circlecube.com/2008/12/asfunction-texteventlink-tutorial-for-as3-flash-html-link-to-call-actionscript-function-tutorial/

This will helps u.

Comments

2

there's no addChild method in TextField. But you may cheat and place button over TextField (i.e. add it to container of a TextField).

Comments

2

Short answer, no. You'd need to make a wrapper class/MovieClip containing both the button and text field.

3 Comments

I need a particular word as a button.
on a SimpleButton/UIButton (sorry forgot the class)?
UIButton!!! i don't know about that... I wants to assign word as button dynamically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.