如何在Flash(AS3)中扩展舞台上已经准备好的文本字段?

发布于 2024-08-08 23:57:07 字数 483 浏览 2 评论 0原文

我正在寻找一种方法来扩展 Flash (AS3) 舞台上已经准备好的 TextField 像这样:

public class ChildTextField extends TextField 
{
    //code for childTextField comes here    
}

我在舞台上放置了一个实例名称为“thetextfield”的 TextField。现在我想告诉 flash 这个文本字段是 ChildTextField 类型。因此,在我的文档类中,我将该文本字段声明为 ChildTextField:

public class DocumentClass extends Sprite()
{
    public var thetextfield : ChildTextField;
}

这会引发类型强制失败错误。 是否可以像使用库符号一样更改 Flash IDE 中用于文本字段的类?

I'm looking for a way to extend a TextField that's allready on the stage in Flash (AS3)
something like this:

public class ChildTextField extends TextField 
{
    //code for childTextField comes here    
}

I've placed a TextField with instance name 'thetextfield' on the stage. Now I would like to tell flash this textfield is of type ChildTextField. So in my Document Class I declare that textfield as a ChildTextField:

public class DocumentClass extends Sprite()
{
    public var thetextfield : ChildTextField;
}

This throws a Type Coercion failed Error.
Is it possible to change the class that is used for a textfield in the Flash IDE like you can do with library symbols?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音栖息无 2024-08-15 23:57:07

恐怕不是。如果您想添加扩展文本字段类,则必须使用 ActionScript。

编辑:有一种破解方法。来源: http://board.flashkit.com/board/存档/index.php/t-738887.html

事实上,我也遇到过这种情况
之前的问题。就我而言,我是
尝试创建一个文本字段
其他人的额外行为
非编码艺术家使用。我会告诉
你是我原来的解决方案,这就是全部
as3,但是有一个致命的缺陷,而我的
当前的解决方案是
as3 和 jsfl 的组合。

全as3解决方案都很棒,除了
有两件事:首先,它发生在
运行时而不是构建时。那
意味着有一个很小但真实的部分
电影不在的时间
正确初始化。其次,它确实
如果有多个的话就玩不好
电影中的帧。基本思想是
检测您想要的文本字段
改变,建造东西来取代它们
,然后将它们替换到舞台上。你
可以通过扩展来做到这一点
TextField,或构建一个类
包含一个 TextField 并处理
与它的接口。假设你是
做第一个。添加一个构造函数
SmartTextField 复制所有
您关心的领域:

public function SmartTextField(TextField tf)
{
this.text = tf.text; //continue with copy of anything relevant. 
}

在你的主要电影中有代码
检测并替换文本字段
你想替换

 var toreplace:Array = findTextFields(); 
 var tf:TextField;
 var stf:SmartTextField; 
 var where:int;
 for (int i = 0; i < toreplace.length;i++)
 { tf = TextField(toreplace[i]);
   stf = new SmartTextField(tf); 
   where = getChildIndex(tf); 
    addChildAt(stf,where); 
    removeChild(tf); 
 }

除了点之外,这工作得很好
如上所述。

JSFL 解决方案有点太复杂
详细介绍一下,但这是
基础知识。有一个包装的 as3 类
包含您的新行为的文本字段
想。编写一个 jsfl 脚本,其中
迭代选定的项目,并且
如果它是文本字段,则转换为
带有新的基类的符号
包装类。这样做有以下优点
它发生在作者时间,并且
诸如位置、实例名称之类的东西
其他的东西是自动的
保存下来。它有一个缺点
jsfl 有很多烦人的地方
需要解决的怪癖。

编辑:当然,如果这只是为了
单部电影,你可以放弃
jsfl 转换器脚本,然后就可以了
手工。转换为符号 ->包装纸
基类。

Afraid not. You will have to use ActionScript if you want to add your extended textfield class.

EDIT: there is a hack way. source: http://board.flashkit.com/board/archive/index.php/t-738887.html

Actually, I've run into this exact
problem before. In my case, I was
trying to create a textfield with
extra behaviors for other some other
non-coder artists to use. I'll tell
you my original solution which is all
as3, but had a fatal flaw, and my
current solution, which is a
combination of as3 and jsfl.

The all as3 solution is great except
for 2 things: First, it happens at
runtime rather than build-time. That
means there's a small but real portion
of time where the movie isn't
correctly initialized. Second, it does
not play well if there are multiple
frames in the movie. The basic idea is
to detect the TextFields you want to
change, build things to replace them
with, then replace them on stage. You
can do this with either by extending
TextField, or building a class which
contains a TextField and handles the
interface to it. Let's say you're
doing the first. Add a constructor to
SmartTextField that copies all the
fields you care about:

public function SmartTextField(TextField tf)
{
this.text = tf.text; //continue with copy of anything relevant. 
}

in your main movie have code which
detects and replaces the TextFields
you want to replace

 var toreplace:Array = findTextFields(); 
 var tf:TextField;
 var stf:SmartTextField; 
 var where:int;
 for (int i = 0; i < toreplace.length;i++)
 { tf = TextField(toreplace[i]);
   stf = new SmartTextField(tf); 
   where = getChildIndex(tf); 
    addChildAt(stf,where); 
    removeChild(tf); 
 }

This works fine, except for the points
above.

The JSFL solution is a bit too complex
to go over in detail, but here's the
basics. Have an as3 class which wraps
a textfield with the new behavior you
want. Write a jsfl script which
iterates over the selected items, and
if it's a textfield, converts to a
symbol with a baseclass of your new
wrapper class. This has the advantages
that it happens at author time, and
things like position, instancename and
other stuff is automatically
preserved. It has the disadvantage
that jsfl has a lot of little annoying
quirks to work through.

edit: Of course, if this is only for a
single movie, you could forego the
jsfl converter script, and just do it
by hand. convert to symbol -> wrapper
baseclass.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文