URLRequest 或 Loader 在某些计算机上根本无法工作?

发布于 2024-09-15 21:07:27 字数 4699 浏览 8 评论 0原文

所以我的问题可能比这更大一点,但我不确定。我正在为客户端创建一个自定义 Flash 照片查看器,该客户端使用 Loader 对象动态加载图像。它获取服务器上指定目录中的文件夹名称,并调用 php 页面(使用 URLRequest)来获取该文件夹的可用内容。然后它从该数组加载它。

问题是:它在我的机器以及我测试过的每台机器上运行良好,但在我客户的机器或他的一些客户的机器上不起作用。屏幕底部的加载器栏没有开始填充,这意味着图像甚至没有开始加载,状态栏指示它继续等待服务器,但永远不会完成等待。这在单台机器上是一致的,但在不同机器上会有所不同。

我已经向该事物添加了诊断(我为跟踪某些变量并收集错误而创建的自定义类)以捕获任何错误,但它在我的客户端计算机上没有报告任何内容。我添加了闪存版本检查代码,因此较低版本弄乱它的可能性已经消失了...

我想我的问题是,是否有任何我可能忽略的东西(安全,环境等)不允许请求对象或某些东西在某些机器上工作?我一直在努力想弄清楚这个问题!

我的代码(相关部分):

    public static const LOADLIMIT:int = 4;

    public var paramObj:Object;
    private var imageRequests:Vector.<URLRequest>;
    private var loaderObj:Vector.<Loader>;
    private var nextToLoad:int = -1;

    //...

    public function Player(){
        //...
        paramObj = loaderInfo.parameters;
            if (!paramObj.root) paramObj.root = "http://site.com/images/";
            paramObj.imgloc = paramObj.imgloc;
            var res = bootstrapImages(paramObj.imgloc);
            if (res is String){
                loadErrorMsg.text = res;
                loadErrorMsg.visible = true;
                log.log(res);
            }
        //...
    }

    private function bootstrapImages(imgloc:String):*{
        try{
        if (!imgloc) return "No image location specified"; 

        var req:URLRequest = new URLRequest(paramObj.root+"getdirlist.php?name="+imgloc);
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, directoryLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, function(ex:IOError){
            loadErrorMsg.text = "Error retreiving album data.";
            loadErrorMsg.visible = true;
            log.log(ex);
        });
        loader.load(req);
        } catch (ex:Error){
            log.log(ex); throw ex;
        }
    }

    private function directoryLoaded(e:Event){
        try{
        //directory will come down as a json array
        trace(e.target.data);
        try {
            var items:Array = JSON.decode(e.target.data);
        } catch (ex:Error){
            trace (ex.getStackTrace());
            loadErrorMsg.text = "Error parsing album data.";
            loadErrorMsg.visible = true;
            log.log(ex);
            return;
        } 

        if (items.length == 0){
            loadErrorMsg.text = "Invalid album name";
            loadErrorMsg.visible = true;
            log.log("Items length is 0.");
            return;
        }

        imageRequests = new Vector.<URLRequest>();
        loaderObj = new Vector.<Loader>();
        for each(var item:String in items){
            imageRequests.push(new URLRequest(paramObj.root+"coffeeimages/"+paramObj.imgloc+"/"+item));
            loaderObj.push(null);
        }

        //...show UI...

        for (var i:int = 0; i < LOADLIMIT; i++){
            imageLoaded(null);
        }
        } catch (ex:Error){
            log.log(ex); throw ex;
        }
    }

    private function imageLoaded(e:Event){
        try{
        //if this was called as a result of the load event, start the slideshow! :D
        if (e != null && e.target != null) {
            //stage.addChild((e.target as LoaderInfo).loader);
            trace(loaderObj[0]);
            if (loaderObj[0] != null && //if the first image is loaded
                loaderObj[0].contentLoaderInfo.bytesLoaded >= loaderObj[0].contentLoaderInfo.bytesTotal){ 
                trace(loaderObj[0].contentLoaderInfo.bytesLoaded, loaderObj[0].contentLoaderInfo.bytesTotal);
                loadErrorMsg.visible = false;
                playSlideshow(true);
            }
        }
        trace((e)?e.target:null, loaderObj);
        nextToLoad++;
        if (nextToLoad >= imageRequests.length) return;

        var r:URLRequest = imageRequests[nextToLoad];
        var l:Loader = new Loader();
        l.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(ex:ErrorEvent){
            loadErrorMsg.text = "Error parsing image data.";
            loadErrorMsg.visible = true;
            log.log(ex);
        });
        l.load(r);
        loaderObj[nextToLoad] = l;
        log.addObjectWatch(l);
        } catch (ex:Error){
            log.log(ex); throw ex;
        }
    }

另外,这里是玩家在网站上直播。 Ctrl+Alt+Home 打开我的诊断面板。如果它对你不起作用,请告诉我,这样我就可以更加担心这个......:/谢谢。

编辑:我添加了更多调试信息。事实证明,在无法加载它的计算机上,当尝试引导专辑信息时,它们会返回 HTTP 状态 0。我不知道这意味着什么......

So my problem may be a little bigger than that, but I'm not certain. I'm creating a custom flash photo viewer for a client that dynamically loads the images with Loader objects. It takes a folder name in a specified directory on the server and calls a php page (using URLRequest) to get the workable contents of the folder. And then it loads it up from that array.

Here's the problem: it works FINE on my machine and every machine I've tested it on, but it DOESN'T work on my client's machine or some of his customer's machines. The loader bar that's at the bottom of the screen doesn't start to fill, which means that the images aren't starting to even load, and the status bar indicates that it continues to wait for a the server, yet never finishes waiting. This is consistent on a single machine, but varies across machines.

I've added diagnostics (a custom class I made to track certain vars and collect errors) to the thing to catch any errors, but it reports nothing on my client's machine. I've added flash version checking code, so the possibility of a lower version messing it up is gone...

I guess my question is, is there anything (security, environment, etc) that I could have overlooked that doesn't allow request objects or something to work on certain machines?? I've been ripping my hair out trying to figure this out!

My code (relevant sections):

    public static const LOADLIMIT:int = 4;

    public var paramObj:Object;
    private var imageRequests:Vector.<URLRequest>;
    private var loaderObj:Vector.<Loader>;
    private var nextToLoad:int = -1;

    //...

    public function Player(){
        //...
        paramObj = loaderInfo.parameters;
            if (!paramObj.root) paramObj.root = "http://site.com/images/";
            paramObj.imgloc = paramObj.imgloc;
            var res = bootstrapImages(paramObj.imgloc);
            if (res is String){
                loadErrorMsg.text = res;
                loadErrorMsg.visible = true;
                log.log(res);
            }
        //...
    }

    private function bootstrapImages(imgloc:String):*{
        try{
        if (!imgloc) return "No image location specified"; 

        var req:URLRequest = new URLRequest(paramObj.root+"getdirlist.php?name="+imgloc);
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, directoryLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, function(ex:IOError){
            loadErrorMsg.text = "Error retreiving album data.";
            loadErrorMsg.visible = true;
            log.log(ex);
        });
        loader.load(req);
        } catch (ex:Error){
            log.log(ex); throw ex;
        }
    }

    private function directoryLoaded(e:Event){
        try{
        //directory will come down as a json array
        trace(e.target.data);
        try {
            var items:Array = JSON.decode(e.target.data);
        } catch (ex:Error){
            trace (ex.getStackTrace());
            loadErrorMsg.text = "Error parsing album data.";
            loadErrorMsg.visible = true;
            log.log(ex);
            return;
        } 

        if (items.length == 0){
            loadErrorMsg.text = "Invalid album name";
            loadErrorMsg.visible = true;
            log.log("Items length is 0.");
            return;
        }

        imageRequests = new Vector.<URLRequest>();
        loaderObj = new Vector.<Loader>();
        for each(var item:String in items){
            imageRequests.push(new URLRequest(paramObj.root+"coffeeimages/"+paramObj.imgloc+"/"+item));
            loaderObj.push(null);
        }

        //...show UI...

        for (var i:int = 0; i < LOADLIMIT; i++){
            imageLoaded(null);
        }
        } catch (ex:Error){
            log.log(ex); throw ex;
        }
    }

    private function imageLoaded(e:Event){
        try{
        //if this was called as a result of the load event, start the slideshow! :D
        if (e != null && e.target != null) {
            //stage.addChild((e.target as LoaderInfo).loader);
            trace(loaderObj[0]);
            if (loaderObj[0] != null && //if the first image is loaded
                loaderObj[0].contentLoaderInfo.bytesLoaded >= loaderObj[0].contentLoaderInfo.bytesTotal){ 
                trace(loaderObj[0].contentLoaderInfo.bytesLoaded, loaderObj[0].contentLoaderInfo.bytesTotal);
                loadErrorMsg.visible = false;
                playSlideshow(true);
            }
        }
        trace((e)?e.target:null, loaderObj);
        nextToLoad++;
        if (nextToLoad >= imageRequests.length) return;

        var r:URLRequest = imageRequests[nextToLoad];
        var l:Loader = new Loader();
        l.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(ex:ErrorEvent){
            loadErrorMsg.text = "Error parsing image data.";
            loadErrorMsg.visible = true;
            log.log(ex);
        });
        l.load(r);
        loaderObj[nextToLoad] = l;
        log.addObjectWatch(l);
        } catch (ex:Error){
            log.log(ex); throw ex;
        }
    }

Also, here's the player live on the site. Ctrl+Alt+Home brings up my diagnostics panel. Please tell me if it doesn't work for you as well, so I can be more worried about this... :/ Thanks.

Edit: I have added more debugging information. Turns out that on the computers that cannot load it, they are getting an HTTP status 0 returned when trying to bootstrap the album information. I have no idea what that means...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

み格子的夏天 2024-09-22 21:07:27

所以,问题是它请求的 URL 的问题......

我的客户正在输入“www.site.com”,而我的代码正在请求“site.com”。对于 Adob​​e 来说,这是跨站点请求,默认情况下不允许。一种解决方案(可能也是最简单的解决方案)是将一个名为“crossdomain.xml”的文件添加到网站的根文件夹中。 Flash 在发出请求时会查找该文件。对我有用的一个例子如下:

//crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
    <allow-access-from domain="*.site.com" secure="false"/>
</cross-domain-policy>

其他解决方案涉及重定向到两者之一(“site.com”重定向到“www.site.com”),或者进行 url 重写,或者获取他们输入的 url。

So, the problem was a matter of the URL its requesting...

My client was typing "www.site.com", while my code was requesting to "site.com". To Adobe, this is a cross site request, and NOT ALLOWED by default. One solution (and probably the easiest one) is to add a file called "crossdomain.xml" to the root folder of the website. Flash looks for this file when making a request. One example that worked for me is as follows:

//crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
    <allow-access-from domain="*.site.com" secure="false"/>
</cross-domain-policy>

Other solutions involve redirecting to one of the two ("site.com" redirects to "www.site.com"), or doing url rewriting, or getting url that they entered.

幽蝶幻影 2024-09-22 21:07:27

我注意到一些事情,您只监听 Event.COMPLETE 和 IOErrorEvent.IO_ERROR。我建议还监听 HTTPStatusEvent.HTTP_STATUS、Event.OPEN,尽管我还没有添加这些内容,但如果您仍然没有任何进展,它们可能会提供有用的信息。

如果您只加载图像而不访问其内容,则不需要 LoaderContext 对象,因此(安全性)确实不应该成为问题。您绝对应该将 imageLoaded 中的逻辑分开,这样它就不会既是 Loaders 的启动程序又是完成处理程序。

不管怎样,不知道这对你是否有用,但我已经让你的代码变得更具可读性,并重新设计了一些没有意义的东西。

public static const LOADLIMIT:int = 4;

private var paramObj:Object;
private var imageRequests:Vector.<URLRequest>;
private var loaderObj:Vector.<Loader>;
private var nextToLoad:int = -1;

public function Player(){
    paramObj = loaderInfo.parameters;

    //what is this all about, your backup URL is useless?
    if (!paramObj.root) {
        paramObj.root = "http://site.com/images/";
    }

    var res = bootstrapImages();
    if (res.length > 0){
        loadErrorMsg.text = res;
        loadErrorMsg.visible = true;
        //log.log kills me
        log.log(res);
    }
}

private function bootstrapImages():String {
    try {
        var req:URLRequest = new URLRequest(paramObj.root + "getdirlist.php?name=" + paramObj.imgloc);
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, directoryLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, dataIOError);
        loader.load(req);
    } catch (ex:Error) {
        log.log(ex);
    }
    return "";
}

private function directoryLoaded(e:Event):void{
    trace(e.target.data);
    try {
        var items:Array = JSON.decode(e.target.data);
    } catch (ex:Error){
        trace (ex.getStackTrace());
        loadErrorMsg.text = "Error parsing album data.";
        loadErrorMsg.visible = true;
        log.log(ex);
        return;
    } 

    if (items.length == 0){
        loadErrorMsg.text = "Invalid album name";
        loadErrorMsg.visible = true;
        log.log("Items length is 0.");
        return;
    }

    imageRequests = new Vector.<URLRequest>();
    loaderObj = new Vector.<Loader>();
    for each(var item:String in items){
        imageRequests.push(new URLRequest(paramObj.root+"coffeeimages/"+paramObj.imgloc+"/"+item));
        loaderObj.push(new Loader());
    }

    for (var i:int = 0; i < LOADLIMIT; i++){
        loadNextImage();
    }
}

private function loadNextImage():void {
    nextToLoad++;
    if (nextToLoad < imageRequests.length) {
        loaderObj[nextToLoad].contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        loaderObj[nextToLoad].contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, dataIOError);
        try {
            loaderObj[nextToLoad].load(imageRequests[nextToLoad]);
        }
        catch (e:Error) {
            log.log(ex);
        }
        log.addObjectWatch(loaderObj[nextToLoad]);
    }
}

private function dataIOError(e:IOError):void {
    loadErrorMsg.text = "IOError: " + e.errorID + " - " + e.name + ", " + e.message;
    loadErrorMsg.visible = true;
    log.log(ex);
}

private function imageLoaded(e:Event){
    //Start the slideshow if the first image has loaded
    loadNextImage();
    if (e.target == loaderObj[0]) {
        trace(loaderObj[0].contentLoaderInfo.bytesLoaded, loaderObj[0].contentLoaderInfo.bytesTotal);
        loadErrorMsg.visible = false;
        playSlideshow(true);
    }
}

编辑:您可能只是希望完全废弃加载代码,而使用 散装装载机

A few things I noticed, you are only listening for Event.COMPLETE and IOErrorEvent.IO_ERROR. I'd suggest also listening for HTTPStatusEvent.HTTP_STATUS, Event.OPEN, though I haven't added those in, they may provide useful information if you still aren't getting anywhere.

You should not need a LoaderContext object if you are only loading images and not accessing their content, so that (security) really should not be a problem. You should definitely separate out your logic in imageLoaded so that it is not both the initiator and the completion handler for your Loaders.

Anyway, no clue if this will be of use to you, but I've made your code substantially more readable and reworked some things that made little sense.

public static const LOADLIMIT:int = 4;

private var paramObj:Object;
private var imageRequests:Vector.<URLRequest>;
private var loaderObj:Vector.<Loader>;
private var nextToLoad:int = -1;

public function Player(){
    paramObj = loaderInfo.parameters;

    //what is this all about, your backup URL is useless?
    if (!paramObj.root) {
        paramObj.root = "http://site.com/images/";
    }

    var res = bootstrapImages();
    if (res.length > 0){
        loadErrorMsg.text = res;
        loadErrorMsg.visible = true;
        //log.log kills me
        log.log(res);
    }
}

private function bootstrapImages():String {
    try {
        var req:URLRequest = new URLRequest(paramObj.root + "getdirlist.php?name=" + paramObj.imgloc);
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, directoryLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, dataIOError);
        loader.load(req);
    } catch (ex:Error) {
        log.log(ex);
    }
    return "";
}

private function directoryLoaded(e:Event):void{
    trace(e.target.data);
    try {
        var items:Array = JSON.decode(e.target.data);
    } catch (ex:Error){
        trace (ex.getStackTrace());
        loadErrorMsg.text = "Error parsing album data.";
        loadErrorMsg.visible = true;
        log.log(ex);
        return;
    } 

    if (items.length == 0){
        loadErrorMsg.text = "Invalid album name";
        loadErrorMsg.visible = true;
        log.log("Items length is 0.");
        return;
    }

    imageRequests = new Vector.<URLRequest>();
    loaderObj = new Vector.<Loader>();
    for each(var item:String in items){
        imageRequests.push(new URLRequest(paramObj.root+"coffeeimages/"+paramObj.imgloc+"/"+item));
        loaderObj.push(new Loader());
    }

    for (var i:int = 0; i < LOADLIMIT; i++){
        loadNextImage();
    }
}

private function loadNextImage():void {
    nextToLoad++;
    if (nextToLoad < imageRequests.length) {
        loaderObj[nextToLoad].contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        loaderObj[nextToLoad].contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, dataIOError);
        try {
            loaderObj[nextToLoad].load(imageRequests[nextToLoad]);
        }
        catch (e:Error) {
            log.log(ex);
        }
        log.addObjectWatch(loaderObj[nextToLoad]);
    }
}

private function dataIOError(e:IOError):void {
    loadErrorMsg.text = "IOError: " + e.errorID + " - " + e.name + ", " + e.message;
    loadErrorMsg.visible = true;
    log.log(ex);
}

private function imageLoaded(e:Event){
    //Start the slideshow if the first image has loaded
    loadNextImage();
    if (e.target == loaderObj[0]) {
        trace(loaderObj[0].contentLoaderInfo.bytesLoaded, loaderObj[0].contentLoaderInfo.bytesTotal);
        loadErrorMsg.visible = false;
        playSlideshow(true);
    }
}

Edit: You may simply wish to scrap your loading code entirely and instead use Bulk Loader

岛歌少女 2024-09-22 21:07:27

我喜欢上面提到的 crossdomain.xml 解决方案,但我们的客户端 PC 上也遇到了类似的问题。问题是 adblocker 浏览器插件阻止了操作脚本的 URLRequest。我们目前正在寻找解决方案。

I like the crossdomain.xml solution mentioned above, but we had a similar problem on our client PC's. The problem was that adblocker browser plugins were blocking the URLRequest of the actionscript. We are currently finding a solution to this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文