ActionScript 中等效的 JavaScript 代码

标签 javascript actionscript-3 apache-flex flash-builder mxml

大家好,我是这两种语言的新手...我在 JavaScript 和 HTML 中找到了一个乱码示例,我想将该代码转换为 ActionScript 代码,这两种语言对我来说看起来很相似,但是当我在 Flash 中编译它时生成器没有任何反应...我想了解如何执行该示例,但在 ActionScript 和 MXML 代码中...

我不明白如何在 ActionScript 中执行的 JavaScript 代码部分:

function check(value)
{
    if ( value != Math.round(value) )
   alert("You must enter an integer in this input box.");
}
function generate( )
{
var minval = parseInt(**document.form.min.value**);
    if ( isNaN(minval) || minval != parseFloat(**document.form.min.value**))

并使用 HTML 中的 TextInput 实现:

<INPUT TYPE="text" NAME="**min**" VALUE="" ONCHANGE="check(**this.value**)">

我不知道将其保留在 AS3 和 MXML 中... 我试过:

public function generate()
{
var minval = parseInt(**min**);
if ( isNaN(minval) || minval != parseFloat(**min**))
{

和 MXML:

<s:TextInput id="**min**" change="**check(this)**" />

如你所见,我很迷茫......

最佳答案

<fx:Script>

<![CDATA[

import flash.events.Event;
import mx.controls.Alert;
public function check(event:Event):void
{               
        if (isNaN(parseInt(min.text)) || isNaN(parseFloat(min.text))) {
            /* Do something here*/
            Alert.show("Input a number", "Error");
        }               
}
]]>
</fx:Script>
<s:TextInput id="min" change="check(event)"/>

我猜这段代码可以按照您想要的方式工作。 请记住,parseInt 函数会忽略有效整数后的任何尾随非数字字符。举例来说,如果您先输入“a”,则代码有效,但如果您输入 1a,则代码失败。可以在此处找到有关该功能的更多详细信息

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package.html#parseInt ()

关于ActionScript 中等效的 JavaScript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13171001/

相关文章:

javascript - 基本的 Node.js 快速身份验证不起作用

javascript - jQuery Counter, animation to a total,但我如何包含一个逗号?

javascript - 当某个节点被选中/取消选中时,自动选中/取消选中 extjs 树中的所有子树节点

apache-flex - 在 TextArea 中实现撤消/重做

javascript - 必须包含小数点的数字的正则表达式

actionscript-3 - 如何在 NetStream 中打开和关闭 H264?

actionscript-3 - AS3 : How to remove movieclip properly without Error 1009 overflow?

apache-flex - 柔性 3 : How to Link to a Flex Project on the Localhost for Testing Purposes

javascript - 动态调整 Flash 对象的大小以填充窗口

apache-flex - 从 Flex 连接到自签名 HTTPS Web 服务