Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 flex中的actionscript放在哪里?_Actionscript 3_Apache Flex - Fatal编程技术网

Actionscript 3 flex中的actionscript放在哪里?

Actionscript 3 flex中的actionscript放在哪里?,actionscript-3,apache-flex,Actionscript 3,Apache Flex,我不理解我相信flex可以运行actionscript的东西,但每次我尝试时都会出现不同的错误 这次我的错误是: Description Resource Path Location Type Could not resolve <fx:script> to a component implementation. as.mxml /ar/src line 7 Flex Problem 描述资源路径位置类型 无法解析为组件实现。as.mxml/ar/src第

我不理解我相信flex可以运行actionscript的东西,但每次我尝试时都会出现不同的错误

这次我的错误是:

Description Resource    Path    Location    Type
Could not resolve <fx:script> to a component implementation.    as.mxml /ar/src line 7  Flex Problem
描述资源路径位置类型
无法解析为组件实现。as.mxml/ar/src第7行Flex问题
我一直在看flex教程,几乎就像他们假设一个人知道ide一样,因此他们只是将.as代码显示出来

我认为flash所能做的一切flex都能做到。那么为什么只限于一个呢

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <fx:script>
        var socket:XMLSocket;

        stage.addEventListener(MouseEvent.CLICK, doConnect);


        function doConnect(evt:Event):void{
            stage.removeEventListener(MouseEvent.CLICK, doConnect);
            socket = new XMLSocket("127.0.0.1", 9001);
            socket.addEventListener(Event.CONNECT, onConnect);
            socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
            }


        function onConnect(evt:Event):void{
            trace("Connected");
            socket.removeEventListener(Event.CONNECT, onConnect);
            socket.removeEventListener(IOErrorEvent.IO_ERROR, onError);
            socket.addEventListener(DataEvent.DATA, onDataReceived);
            socket.addEventListener(Event.CLOSE, onSocketClose);                
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
            }


        function onSocketClose(evt:Event):void{
            trace("Connection Closed");
            stage.removeEventListener(KeyboardEvent.KEY_UP, keyUp);
            socket.removeEventListener(Event.CLOSE, onSocketClose);
            socket.removeEventListener(DataEvent.DATA, onDataReceived);
            }

        function keyUp(evt:KeyboardEvent):void{
            if(evt.keyCode == 81){
                socket.send("exit");
                }
            else{
                socket.send(evt.keyCode);
                }}

        function onDataReceived(evt:DataEvent):void{
            try{
                trace( "From Server:", evt.data );
                }
            catch(e:Error){
                trace('error');
                }}



        function onError(evt:IOErrorEvent):void{
            trace("Connect failed");
            socket.removeEventListener(Event.CONNECT, onConnect);
            socket.removeEventListener(IOErrorEvent.IO_ERROR, onError);
            stage.addEventListener(MouseEvent.CLICK, doConnect);
            }
    </fx:script>
</fx:Declarations>

var-socket:XMLSocket;
stage.addEventListener(MouseEvent.CLICK,doConnect);
函数doConnect(evt:事件):无效{
stage.removeEventListener(MouseEvent.CLICK,doConnect);
套接字=新的XMLSocket(“127.0.0.1”,9001);
socket.addEventListener(Event.CONNECT、onConnect);
socket.addEventListener(IOErrorEvent.IO_ERROR,onError);
}
连接函数(evt:事件):无效{
跟踪(“连接”);
socket.removeEventListener(Event.CONNECT,onConnect);
socket.removeEventListener(IOErrorEvent.IO_ERROR,onError);
socket.addEventListener(DataEvent.DATA,onDataReceived);
socket.addEventListener(Event.CLOSE、onSocketClose);
stage.addEventListener(KeyboardEvent.KEY\u UP,keyUp);
}
onSocketClose函数(evt:事件):无效{
跟踪(“连接关闭”);
stage.removeEventListener(KeyboardEvent.KEY\u UP,keyUp);
socket.removeEventListener(Event.CLOSE、onSocketClose);
socket.removeEventListener(DataEvent.DATA,onDataReceived);
}
功能键控(evt:KeyboardEvent):无效{
如果(evt.keyCode==81){
套接字。发送(“退出”);
}
否则{
套接字发送(evt.keyCode);
}}
函数onDataReceived(evt:DataEvent):void{
试一试{
跟踪(“来自服务器:”,evt.data);
}
捕获(e:错误){
跟踪(“错误”);
}}
函数onError(evt:IOErrorEvent):无效{
跟踪(“连接失败”);
socket.removeEventListener(Event.CONNECT,onConnect);
socket.removeEventListener(IOErrorEvent.IO_ERROR,onError);
stage.addEventListener(MouseEvent.CLICK,doConnect);
}

首先,确保使用带有大写字母S的
fx:Script
;不是小写的S

然后将您的
fx:Script
标记移出
fx:Declaration
,您的代码将编译:

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

    <fx:Script>
        var socket:XMLSocket;

        stage.addEventListener(MouseEvent.CLICK, doConnect);


        function doConnect(evt:Event):void{
            stage.removeEventListener(MouseEvent.CLICK, doConnect);
            socket = new XMLSocket("127.0.0.1", 9001);
            socket.addEventListener(Event.CONNECT, onConnect);
            socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
            }


        function onConnect(evt:Event):void{
            trace("Connected");
            socket.removeEventListener(Event.CONNECT, onConnect);
            socket.removeEventListener(IOErrorEvent.IO_ERROR, onError);
            socket.addEventListener(DataEvent.DATA, onDataReceived);
            socket.addEventListener(Event.CLOSE, onSocketClose);                
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
            }


        function onSocketClose(evt:Event):void{
            trace("Connection Closed");
            stage.removeEventListener(KeyboardEvent.KEY_UP, keyUp);
            socket.removeEventListener(Event.CLOSE, onSocketClose);
            socket.removeEventListener(DataEvent.DATA, onDataReceived);
            }

        function keyUp(evt:KeyboardEvent):void{
            if(evt.keyCode == 81){
                socket.send("exit");
                }
            else{
                socket.send(evt.keyCode);
                }}

        function onDataReceived(evt:DataEvent):void{
            try{
                trace( "From Server:", evt.data );
                }
            catch(e:Error){
                trace('error');
                }}



        function onError(evt:IOErrorEvent):void{
            trace("Connect failed");
            socket.removeEventListener(Event.CONNECT, onConnect);
            socket.removeEventListener(IOErrorEvent.IO_ERROR, onError);
            stage.addEventListener(MouseEvent.CLICK, doConnect);
            }
    </fx:Script>

var-socket:XMLSocket;
stage.addEventListener(MouseEvent.CLICK,doConnect);
函数doConnect(evt:事件):无效{
stage.removeEventListener(MouseEvent.CLICK,doConnect);
套接字=新的XMLSocket(“127.0.0.1”,9001);
socket.addEventListener(Event.CONNECT、onConnect);
socket.addEventListener(IOErrorEvent.IO_ERROR,onError);
}
连接函数(evt:事件):无效{
跟踪(“连接”);
socket.removeEventListener(Event.CONNECT,onConnect);
socket.removeEventListener(IOErrorEvent.IO_ERROR,onError);
socket.addEventListener(DataEvent.DATA,onDataReceived);
socket.addEventListener(Event.CLOSE、onSocketClose);
stage.addEventListener(KeyboardEvent.KEY\u UP,keyUp);
}
onSocketClose函数(evt:事件):无效{
跟踪(“连接关闭”);
stage.removeEventListener(KeyboardEvent.KEY\u UP,keyUp);
socket.removeEventListener(Event.CLOSE、onSocketClose);
socket.removeEventListener(DataEvent.DATA,onDataReceived);
}
功能键控(evt:KeyboardEvent):无效{
如果(evt.keyCode==81){
套接字。发送(“退出”);
}
否则{
套接字发送(evt.keyCode);
}}
函数onDataReceived(evt:DataEvent):void{
试一试{
跟踪(“来自服务器:”,evt.data);
}
捕获(e:错误){
跟踪(“错误”);
}}
函数onError(evt:IOErrorEvent):无效{
跟踪(“连接失败”);
socket.removeEventListener(Event.CONNECT,onConnect);
socket.removeEventListener(IOErrorEvent.IO_ERROR,onError);
stage.addEventListener(MouseEvent.CLICK,doConnect);
}

fx:Declaration
标记主要用于非可视的MXML组件,例如验证器或服务。虽然
fx:Script
显然是非可视的,但它通常不会嵌入
fx:Declaration

中,所以组件是可以在flash中构建的,然后导出为swc,在flex应用程序中使用,并添加到构建中,然后在声明中引用?@BenMuircroft这取决于您如何定义“组件”。根据我的经验,Flash Pro中唯一内置并导出用于Flex的是库资产;通常是图形资源和/或动画。在Flash Builder(或IntelliJ或任何您选择的IDE)中,其他所有内容通常都是直接为Flex构建的。我认为您可以设计一个复杂的菜单或应用程序部分(外观非常奇怪,图形化程度很高),在其框架中使用as3,然后将其转换为Flex中使用的组件。因为flex不做图形。理论上;你可以。从来没有人这样做过。如果你想设计复杂/古怪的菜单,为什么首先要使用Flex?如果您没有使用内置flex组件/设置其样式;我不知道你为什么要用Flex。