lundi 26 septembre 2016

as3 dynamic TextField words from array placed into individual MovieClips into a sentence

I am trying to create a dynamic sentence from an array of words. The words need to be placed next to each other in a sentence. I need the words to be in a movie clip so I can drag them as well.

Below is the code I am using but I am having many issues. Any ideas?

package com.sentances {

    import flash.display.MovieClip;
    import flash.display.*;
    import flash.text.*;

    public class Main_Sentances extends MovieClip {

        public var Sentance: Array;
        public var myText: TextField;
        public var myMovie: MovieClip;

        public var Words: Array = new Array("This", "is", "my", "sentance.");

        public function Main_Sentances() {
            // constructor code


        public function MakeWords() {
            var xSpot = 0;
            for (var i = 0; i < Words.length; i++) {

                myMovie = new MovieClip();
       = Words[i];

                myText = new TextField();
                myText.selectable = false;
                myText.border = true;
                myText.defaultTextFormat = new TextFormat('Verdana', 50, 0xffffff);
                myText.text = Words[i];


                myText.addEventListener(Event.ADDED_TO_STAGE, handleChng);

                function handleChng(e: Event): void {
                    trace("childMC ADDED_TO_STAGE");

                        myMovie.x = 0;
                        myMovie.width = myText.textWidth;
                        myMovie.height = myText.textHeight;
                        xSpot = myText.textWidth;
                        myMovie.width = myText.textWidth;
                        myMovie.height = myText.textHeight;
                        xSpot = xSpot + myText.textWidth;
                        myMovie.x = xSpot;



        // End Package  

Aucun commentaire:

Enregistrer un commentaire