当平假名 IME 处于活动状态时以编程方式将字符添加到 TextInput
我希望能够以编程方式向 TextInput 添加字符(例如,当您按下按钮时),即使在使用 IME 时(我现在正在使用日语 IME)。通常这非常简单,即
protected function button_clickHandler(event:MouseEvent):void
{
ti.text = "k";
}
ti 是一个 TextInput 组件。然而,使用输入法时,事情会变得有点棘手。例如,即使您使用的是平假名输入法,上面的代码也会在 ti 中添加 ak。 我查看了 IME 文档并尝试了类似的方法,
protected function button_clickHandler(event:MouseEvent):void
{
IME.setCompositionString("k");
}
一开始我认为这可以解决问题,但它似乎总是默认为半角片假名(尽管我不是 100% 确定),即使当前选择平假名转换模式,或者如果我在设置组合字符串之前设置它。不幸的是,IME 库似乎不是开源的,所以我不知道这是否是一个错误。
想知道是否有人有任何建议 - 我意识到这是非常具体的,所以可能性很低,但我想我会尝试。
谢谢你!
后期编辑:这里有一些代码来尝试我正在谈论的内容。注意:您的计算机上需要安装日语输入法。我在带有日语 IME 设置的 Windows 7 机器上使用它,并在独立的 Flash 上运行它。很难看出用平假名和片假名输入 ak 之间的区别,但如果仔细观察,您应该会注意到差异(如果您在输入“a”后立即输入“a”,您应该会看到弹出的不同结果)。
<?xml version="1.0"?>
<!-- dpcontrols/adg/SimpleADG.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
protected function button_clickHandler(event:MouseEvent):void
{
ti.setFocus();
try
{
IME.enabled = true;
IME.conversionMode = IMEConversionMode.JAPANESE_HIRAGANA;
IME.setCompositionString("k");
}
catch (error:Error)
{
trace("Unable to set conversion mode.\n" + error.message);
}
}
]]>
</fx:Script>
<s:VGroup>
<s:TextInput id="ti"/>
<s:Button label="go" click="button_clickHandler(event)"/>
</s:VGroup>
</s:Application>
I'd like to be able to add a character to a TextInput programmatically (say when you press a button) even when using IMEs (I'm using a Japanese IME right now). Normally this would be super easy, i.e.
protected function button_clickHandler(event:MouseEvent):void
{
ti.text = "k";
}
where ti is a TextInput component. However, things get a little tricky when using an IME. The code above, for instance, adds a k in ti even if you're using the Hiragana IME.
I looked at the IME documentation and tried something like this
protected function button_clickHandler(event:MouseEvent):void
{
IME.setCompositionString("k");
}
at first I thought this was doing the trick, but it seems like it always defaults to what looks like Half-Width Katakana (although I'm not 100% sure), even if the Hiragana conversionMode is currently selected, or if I set it right before setting the composition string. Unfortunately the IME library doesn't seem to be open source so I have no idea if this is a bug or not.
Was wondering if anyone had any advice - I realize this is super specific so the odds are low, but thought I'd try.
thank you!
post-edit: here is some code to try out what I'm talking about. Note: you'll need Japanese IME setup on your machine. I'm using this on a Windows 7 box with Japanese IME setup, and running it on standalone Flash. It's hard to see the difference between typing a k in Hiragana and in Katakana, but if you look closely you should notice a difference (and if you type an 'a' right after you should see different results popping up).
<?xml version="1.0"?>
<!-- dpcontrols/adg/SimpleADG.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
protected function button_clickHandler(event:MouseEvent):void
{
ti.setFocus();
try
{
IME.enabled = true;
IME.conversionMode = IMEConversionMode.JAPANESE_HIRAGANA;
IME.setCompositionString("k");
}
catch (error:Error)
{
trace("Unable to set conversion mode.\n" + error.message);
}
}
]]>
</fx:Script>
<s:VGroup>
<s:TextInput id="ti"/>
<s:Button label="go" click="button_clickHandler(event)"/>
</s:VGroup>
</s:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,查看此链接:http://livedocs。 adobe.com/flex/3/html/help.html?content=18_Client_System_Environment_6.html
确保您已启用 IME 并进行正确的设置。其次,你使用什么版本的flex?您是否有加载到应用程序中的可以处理该语言的字体?
First, look at this link: http://livedocs.adobe.com/flex/3/html/help.html?content=18_Client_System_Environment_6.html
Make sure you have IME enabled and the proper settings. Second, what version of flex are you using? Do you have a font that's loaded into the application that can handle the language?
提交了一个错误 - 我们会看看 Adobe 怎么说。
filed a bug - we'll see what Adobe says.