ActionScripts3从服务器问题

时间:2017-01-30 09:17:47

标签: xml actionscript-3

我在 LocalHost 上有一个示例XML,我写了一些代码来阅读它的数据,它工作正常但是当我上传到 Byethost 服务器时它工作正常在网络浏览器上,但在 Adob​​e Animate 中返回错误。

XML示例:

<?xml version="1.0" encoding="UTF-8"?>
<Data>

    <D1>1</D1>
    <D2>2</D2>
    <D3>3</D3>

</Data>

AS3代码:

import flash.events.Event; 
import flash.net.URLLoader; 

var myXML:XML = new XML(); 
var XML_URL:String = "http://example.com/api/data.xml"; 
var myXMLURL:URLRequest = new URLRequest(XML_URL); 
var myLoader:URLLoader = new URLLoader(myXMLURL); 
myLoader.addEventListener(Event.COMPLETE, xmlLoaded); 

function xmlLoaded(event:Event):void 
{ 
    myXML = XML(myLoader.data); 
    trace(myXML.D1); 
    trace(myXML.D2); 
    trace(myXML.D3); 

}

从ActionScripts3中读取 localhost 中的XML时的输出:

1 2 3

使用网络浏览器时的输出:

1 2 3

从ActionScripts3读取服务器中的XML( byet.host )时的输出:

TypeError: Error #1085: The element type "d.length;f++)e+=(16" must be terminated by the matching end-tag "</d.length;f++)e+=(16>".

来自调试模式的消息:

Attempting to launch and connect to Player using URL E:\PROJECTS\1. ANIMATE\XML\RECOVER_xml.swf
[SWF] E:\PROJECTS\1. ANIMATE\XML\RECOVER_xml.swf - 1802 bytes after decompression
*** Security Sandbox Violation ***
Connection to http://example.com/api/data.xml halted - not permitted from file:///E|/PROJECTS/1.%20ANIMATE/XML/RECOVER%5Fxml.swf
-- Untrusted local SWFs may not contact the Internet.
SecurityError: Error #2028: Local-with-filesystem SWF file file:///E|/PROJECTS/1.%20ANIMATE/XML/RECOVER%5Fxml.swf cannot access Internet URL http://example.com/api/data.xml.
    at flash.net::URLStream/load()
    at flash.net::URLLoader/load()
    at flash.net::URLLoader()
    at RECOVER_xml_fla::MainTimeline/frame1()[RECOVER_xml_fla.MainTimeline::frame1:7]
Cannot display source code at this location.

解决方案

*Free hosts doesn't support direct access to files. It is possible to use google drive for access directly to a file and read it's content.*

This site helped me to solve this problem:

http://www.syncwithtech.org/p/direct-download-link-generator.html

2 个答案:

答案 0 :(得分:1)

首先,我会在xmlLoaded方法的第一行放置一个断点,然后启动调试会话Debug->Debug。 看起来你得到格式错误的xml数据,所以在调试模式下检查myLoader.data - 它应该给你一个答案

答案 1 :(得分:1)

这是违反安全规定的行为。如果您打算在本地测试您的应用程序,那么您可以使用全局安全设置来允许它:http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

如果您要使用来自域A的应用程序从域B加载XML,则应允许在域B上放置跨域策略:http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e08.html