UDK Scaleform 4 AS3 跨域 URLRequest 可能吗?

Posted

技术标签:

【中文标题】UDK Scaleform 4 AS3 跨域 URLRequest 可能吗?【英文标题】:UDK Scaleform 4 AS3 cross-domain URLRequest possible? 【发布时间】:2012-11-17 15:34:49 【问题描述】:

我想使用在线 mysql 数据库、Scaleform 4 (AS3) 和 php,通过 HTTP 请求将我的 UDKGame 的高分发布到我的网络服务器。不幸的是,考虑到这份文件,我认为这可能是不可能的:http://gameware.autodesk.com/documents/gfx_4.0_flash_support.pdf。

我尝试从我的 GFx 电影播放器​​发送 URLRequest,但它似乎不起作用。这是我在第 1 帧中用于 GFx 电影播放器​​的 AS3 代码:

getScore();

function getScore():void 
//var url:String = "http://myserver.com/getScore.php";
    var request:URLRequest = new URLRequest(url);
    var requestVars:URLVariables = new URLVariables();
    requestVars.foo = "bar";
    request.data = requestVars;
    //request.method = URLRequestMethod.POST;
    //Security.allowDomain("myserver.com"); 
    //var context:LoaderContext = new LoaderContext();
    //context.securityDomain = SecurityDomain.currentDomain

    var urlLoader:URLLoader = new URLLoader();
    urlLoader = new URLLoader();
    urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
    urlLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler, false, 0, true);
    urlLoader.load(request);

    

function loaderCompleteHandler(e:Event):void 
    trace(e.target.data);
    Object(this).response.text= "response:"+e.target.data;


有什么方法可以在不编写 .dll 或使用手动 TCP 连接到我的网络服务器的情况下实现我的目标?

【问题讨论】:

【参考方案1】:

不幸的是,UDK (4.0.16) 附带的 Scaleform 没有内置任何网络支持。您必须让 UDK 通过 dll 绑定或其他方式解决该问题。 Scaleform 4.2 添加了网络支持,但该版本的 Scaleform 尚未完全集成到 UDK 中。不过它正在整合中,所以希望我们很快就能看到它。

【讨论】:

【参考方案2】:

SF4.0 确实不支持。 SF4.2也许可以,而且它只提供给 UE3 被许可人,通过 Epic 的 Perforce 软件仓库。

你可以在虚幻脚本中做到这一点。然而,使用 dll 或 TCP 连接有点矫枉过正。使用HttpRequestInterface。这是直接来自随 UDK 提供的源示例的示例。它非常简单,您可以将其缩减到只用几行代码就可以调用您的网络服务的严格要求。

/**
 * Simple function to illustrate the use of the HttpRequest system.
 */
exec function TestHttp(string Verb, string Payload, string URL, optional bool bSendParallelRequest)

    local HttpRequestInterface R;

    // create the request instance using the factory (which handles
    // determining the proper type to create based on config).
    R = class'HttpFactory'.static.CreateRequest();
    // always set a delegate instance to handle the response.
    R.OnProcessRequestComplete = OnRequestComplete;
    `log("Created request");
    // you can make many requests from one request object.
    R.SetURL(URL);
    // Default verb is GET
    if (Len(Verb) > 0)
    
        R.SetVerb(Verb);
    
    else
    
        `log("No Verb given, using the defaults.");
    
    // Default Payload is empty
    if (Len(Payload) > 0)
    
        R.SetContentAsString(Payload);
    
    else
    
        `log("No payload given.");
    
    `log("Creating request for URL:"@URL);

    // there is currently no way to distinguish keys that are empty from keys that aren't there.
    `log("Key1 ="@R.GetURLParameter("Key1"));
    `log("Key2 ="@R.GetURLParameter("Key2"));
    `log("Key3NoValue ="@R.GetURLParameter("Key3NoValue"));
    `log("NonexistentKey ="@R.GetURLParameter("NonexistentKey"));
    // A header will not necessarily be present if you don't set one. Platform implementations
    // may add things like Content-Length when you send the request, but won't necessarily
    // be available in the Header.
    `log("NonExistentHeader ="@R.GetHeader("NonExistentHeader"));
    `log("CustomHeaderName ="@R.GetHeader("CustomHeaderName"));
    `log("ContentType ="@R.GetContentType());
    `log("ContentLength ="@R.GetContentLength());
    `log("URL ="@R.GetURL());
    `log("Verb ="@R.GetVerb());

    // multiple ProcessRequest calls can be made from the same instance if desired.
    if (!R.ProcessRequest())
    
        `log("ProcessRequest failed. Unsuppress DevHttpRequest to see more details.");
    
    else
    
        `log("Request sent");
    
    // send off a parallel request for testing.
    if (bSendParallelRequest)
    
        if (!class'HttpFactory'.static.CreateRequest()
            .SetURL("http://www.epicgames.com")
            .SetVerb("GET")
            .SetHeader("Test", "Value")
            .SetProcessRequestCompleteDelegate(OnRequestComplete)
            .ProcessRequest())
        
            `log("ProcessRequest for parallel request failed. Unsuppress DevHttpRequest to see more details.");
        
        else
        
            `log("Parallel Request sent");
        
    



/** Delegate to use for HttpResponses. */
function OnRequestComplete(HttpRequestInterface OriginalRequest, HttpResponseInterface Response, bool bDidSucceed)

    local array<String> Headers;
    local String Header;
    local String Payload;
    local int PayloadIndex;

    `log("Got response!!!!!!! Succeeded="@bDidSucceed);
    `log("URL="@OriginalRequest.GetURL());
    // if we didn't succeed, we can't really trust the payload, so you should always really check this.
    if (Response != None)
    
        `log("ResponseURL="@Response.GetURL());
        `log("Response Code="@Response.GetResponseCode());
        Headers = Response.GetHeaders();
        foreach Headers(Header)
        
            `log("Header:"@Header);
        
        // GetContentAsString will make a copy of the payload to add the NULL terminator,
        // then copy it again to convert it to TCHAR, so this could be fairly inefficient.
        // This call also assumes the payload is UTF8 right now, as truly determining the encoding
        // is content-type dependent.
        // You also can't trust the content-length as you don't always get one. You should instead
        // always trust the length of the content payload you receive.
        Payload = Response.GetContentAsString();
        if (Len(Payload) > 1024)
        
            PayloadIndex = 0;
            `log("Payload:");
            while (PayloadIndex < Len(Payload))
            
                `log("    "@Mid(Payload, PayloadIndex, 1024));
                PayloadIndex = PayloadIndex + 1024;
            
        
        else
        
            `log("Payload:"@Payload);
        
    

【讨论】:

以上是关于UDK Scaleform 4 AS3 跨域 URLRequest 可能吗?的主要内容,如果未能解决你的问题,请参考以下文章

使用 Scaleform 进行游戏资产渲染,而不仅仅是 UI

scaleform 4.4.30 关于opengl的问题

AS3跨域加载SWF文件

ActionScript 3 AS3加载SWF文件跨域

Scaleform 与 Stage3d

链接 Scaleform 以在 Qt Creator 中构建应用程序