如何将动态文本框的不同行转换为AS3中的影片剪辑 [英] How to convert different line of a dynamic text box to Movie clip in AS3

查看:176
本文介绍了如何将动态文本框的不同行转换为AS3中的影片剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于我的项目的问题是如何将动态文本框的不同行转换为AS3中的影片剪辑?其实,我有一个名为test.txt的文本文件。例如:

它包含:


今天是Sun;
今天是星期一;
今天是星期二;
今天是星期三;
今天是星期四;
今天是星期五;
今天是星期六;

然后我想把他们全部放进一个数组,然后一个字符串来显示他们在动态文本框中调用text_txt。

我在库中有不同的对象。如果我们在第一行看到太阳,第一个对象(obj01)将显示在一个名为mc的影片剪辑中的特定区域。



在这里:

拳头:如果我在第一行有不同的文字。比如今天是太阳。如何找到太阳就在这一行???第二:如何将不同的动态文本框的行转换为影片剪辑。所以,如果用户点击obj01,动态文本框中的第一行将变得更大???

感谢您的提前帮助。

  import flash.events.MouseEvent; 

var flag:int = 0;


//载入txt文件
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE,onLoaded);
myTextLoader.load(new URLRequest(test.txt));

//当场景加载时,所有信息从txt文件显示到动态文本中;
函数onLoaded(e:Event):void
{
//将所有信息放入数组
var days:Array = e.target.data.split(/ \ N /);

var str:String;
//在动态文本
中显示它们(var i = 0; i {
str = days [i];
text_txt.appendText(str +\\\
);

//如果创建了一个文本,做一些事情并在输出结果中提供一个对象;
switch(str)
{
casesun; \r:
var obj01:Show = new Show();
mc.addChild(obj01);
obj01.x = -200;
obj01.y = -15;
break;

默认值:
trace(以上都不符合);
}
}

obj01.buttonMode = true;


//如果点击了对象,那么动态文本框中的第一行必须发生一些事情。
obj01.addEventListener(MouseEvent.CLICK,firstLine);
函数firstLine(e:MouseEvent):void
{
flag = 1;

switch(flag)
{
case 1:
trace(Clicked!);
//文本框中的第一行应该获得不同的背景并变得更大
//是否需要将第一行转换为动画片段?或者我需要以另一种方式来做?
break;

默认值:
trace(None);




$ div class =h2_lin>解决方案我确信必须有办法做到这一点,这就是为什么我把它作为我最喜欢的问题。

  // 
var newMcTitle:Array = [];

//将所有信息存入数组
var days:Array = e.target.data.split(/ \\\ n /);

for(var i = 0; i {
str = days [i];

//将文本逐行放入文本字​​段,并将文本字段放入影片剪辑
var newMc:MovieClip = new MovieClip();
var newText:TextField = new TextField();
newText.text = days [i];
newMc.addChild(newText);
newMc.x = 30;
newMc.y = positionY;
newMc.scaleX = 2;
newMc.scaleY = 2;
addChild(newMc);
positionY + = 30;

//独特的实例名称:
newMc.name = days [i]; //或者当没有数组时使用
newMc.name ='mc_'+ i;
//trace(newMc.name);

//分配独特的属性来识别newMc
newMc.ivar = i;

//填充在for循环外部实例化的数组(例如,var newMcA:Array = [];)
newMcTitle.push(newMc);

$ / code>

现在您可以使用:

  // //如果点击了对象,那么动态文本框中的第一行必须发生一些事情
obj01.addEventListener(MouseEvent.CLICK,firstLine);
函数firstLine(e:MouseEvent):void
{
flag01 + = 1;

switch(flag01)
{
案例1:
//文本框中的第一行应该获得不同的背景并变得更大
newMcTitle [0] .scaleX * = 1.2;
newMcTitle [0] .scaleY * = 1.2;
break;

默认值:
trace(None);
}
}


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:

today is Sun; today is Mon; today is Tue; today is Wed; today is Thu; today is Fri; today is 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 (obj01) will be shown in a specific area which is inside a movie clip called mc.

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, if user click on the "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");
    }
  }
}

解决方案

After too much research and try a lot of functions, I have find the answer for Second part of this question. I was sure that there must be a way to do it and that's why I made it as my Favorite question.

//
var newMcTitle:Array = [];

//put all the info into array
var days:Array = e.target.data.split(/\n/);

for (var i=0; i<days.length; i++)
{
    str = days[i];

    //put the texts line by line into a textfield and put the textfield into a movie clip
    var newMc:MovieClip = new MovieClip();
    var newText:TextField = new TextField();
    newText.text = days[i];
    newMc.addChild(newText);
    newMc.x = 30;
    newMc.y = positionY;
    newMc.scaleX = 2;
    newMc.scaleY = 2;
    addChild(newMc);
    positionY +=  30;

    //unique instance names:
    newMc.name = days[i];// or more generally when no arrays used
    newMc.name = 'mc_' + i;
    //trace(newMc.name);

    //asssign unique property to be used to identify newMc
    newMc.ivar = i;

    //populate an array instantiated outside for-loop (eg, var newMcA:Array=[];)
    newMcTitle.push(newMc);
}

And now you can use:

//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
{
    flag01 +=  1;

    switch (flag01)
    {
        case 1 :
            //the first line in the text box should get a different background and become more bigger
            newMcTitle[0].scaleX *=  1.2;
            newMcTitle[0].scaleY *=  1.2;
            break;

        default :
            trace("None");
    }
}

这篇关于如何将动态文本框的不同行转换为AS3中的影片剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆