dimanche 11 décembre 2016

How to convert different line of a dynamic text box to Movie clip in AS3

I have a question regarding to my project which is How to convert different line of a dynamic text box to Movie clip in AS3?

Actually, I have an text file named test.txt. For instance:

It consists of: Sun;Mon;Tue;Wed;Thu;Fri;Sat;

and then I want to put all of them into an array and then a string to show them in the dynamic text Box called text_txt.

I have different objects in my library. If we see "sun;" in the first line, the first object will be shown in a specific area on my movie clip.

The question is here:

Fist: if I have different texts in my first line. for instance "today is sun;". how to find that the "sun" is in this line???

Second: How to convert different line of a dynamic text box to Movie clip. So, is user click on the "mc.obj01", the first line in the dynamic textbox will become bigger???

Thanks for your time and help in advance.

import flash.events.MouseEvent;

var flag:int = 0;


//load the txt file
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
myTextLoader.load(new URLRequest("test.txt"));

//when the scene loads, all the info from txt file shown into the dynamic text;
function onLoaded(e:Event):void
{
//put all the info into array
var days:Array = e.target.data.split(/\n/);

var str:String;
//show them in the dynamic text
for (var i=0; i<days.length; i++)
{
    str = days[i];
    text_txt.appendText(str + "\n");

    //if one text founded, do somethind and shoe an objectinthe output;
    switch (str)
    {
        case "sun;\r" :
            var obj01:Show = new Show();
            mc.addChild(obj01);
            obj01.x = -200;
            obj01.y = -15;
            break;

        default :
            trace("None of the above were met");
    }
}

obj01.buttonMode = true;


//if the object clicked then something must be happend to the first line in the dynamic text box
obj01.addEventListener(MouseEvent.CLICK, firstLine);
function firstLine(e:MouseEvent):void
{
    flag = 1;

    switch (flag)
    {
        case 1 :
            trace("Clicked!");
            //the first line in the text box should get a different background and become more bigger
            //Do I need to convert the first line to a movieclip? OR I need to do in another way?! 
            break;

        default :
            trace("None");
    }
}

}

Aucun commentaire:

Enregistrer un commentaire