在 AS3 中使用 ruturn 的 addEventListener - 如何? [英] addEventListener with ruturn in AS3 - How?

查看:59
本文介绍了在 AS3 中使用 ruturn 的 addEventListener - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的 Flash AS3 工作,但是当我需要一个事件侦听器代码时,我在使用一些 OOP 概念(例如从方法返回)时遇到了大问题.问题是来自事件侦听器的函数无法返回值.我该如何处理这个问题?这是我在 AIR 应用程序上使用的代码示例.这段代码我想在我想解析目录文件的其他情况下重用.

I'm a new Flash AS3 job but I have a big problem using some OOP concepts like return from methods, when I needs a Event Listener code. The problem is that the function from Event Listener cannot return a value. How can I work with this issue? This is a code sample that I using on my AIR app. This code I want to re-use in other situations that I want to parse a directory files.

private function initApp():void
{
    try
    {
        // Seta o diretoório de molduras
        var directory = diretorio_mestre.resolvePath("molduras/animacao");
        directory.getDirectoryListingAsync();
        directory.addEventListener(FileListEvent.DIRECTORY_LISTING, listaHandler);

    }
    catch (erro:ReferenceError)
    {
        mostraMensagem("Problemas com a listagem do diretório.", erro.errorID);

    }

    // Percorre arquivos
    function listaHandler(evento):void
    {
        // Contador
        var i:int = 0;

        // Conteúdo
        var contents = evento.files;

        for (i = 0; i < contents.length; i++) 
        {
            var nome:String = contents[i].name;
            var nome_array:Array = new Array();
            nome_array = nome.split("_");

            // Formata para ordenar
            arquivos_animacao.push ( { nome:contents[i].name, tamanho:contents[i].size, ordem:nome_array[0] } );

        }

        // Ordena para a ordem de númeração
        arquivos_animacao.sortOn("ordem", Array.NUMERIC);

        // Continua o processo
        // How can I return!?!?!

    }

}

推荐答案

如果我正确理解您的问题,您想在调度事件的同时传递额外的参数吗?这是 flash/air 的一个常见问题,它只是意味着您需要创建一个自定义事件并使用额外的参数对其进行扩展.

If I understand your question correctly, you want to pass extra arguments along with a dispatched event? This is a common issue with flash / air, and it just means you need to create a custom event and extend it with extra parameters.

不久前我发表了一篇文章,详细说明了如何在此处执行此操作:如何实现自定义事件".

I made a post not too long ago detailing how to do this right here: "how to implement custom events".

主要思想是在分派事件时在方法 sig 的末尾传递参数,并在接收端将它们作为数组拾取.

The main idea is you pass arguments at the end of the method sig when dispatching the event, and picking them up as an array on the receiving end.

希望有帮助

这篇关于在 AS3 中使用 ruturn 的 addEventListener - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆