flash - 为什么我不能在 Flash CS4 的回调方法中访问组合框?

标签 flash actionscript-2 flash-cs4

检查这段代码:

import mx.core.View;
var accordianPane = my_acc.createSegment("mcElectrical", "panel0", "Electrical", "payIcon");
accordianPane.comboBox.addItem("test");

这会将标签为“test”的项目添加到影片剪辑的组合框中。它工作得很好。但是,当我将相同的代码放入回调函数时,它失败了。

import mx.core.View;

// Load Cost Guide feed.
var costGuideUrl:String = "http://test/cost-guide.ashx";
var costGuideXml:XML = new XML();
costGuideXml.onLoad = function(success) {
    if(success) { 
        populateAccordian(this); 
    } else {
        // Display error message.
    }
};
costGuideXml.load(costGuideUrl);

// Populate Accordian with retrieved XML.
function populateAccordian(costGuideXml:XML) {

    var accordianPane = my_acc.createSegment("mcElectrical", "panel0", "Electrical", "payIcon");
    accordianPane.comboBox.addItem("test");
    // This line definitely executes...
}

关于为什么我无法从回调内部进入组合框的任何想法?

最佳答案

好的,首先看起来您使用的是 AS2。

由于是 as2,问题可能是范围问题。作用域在 as2 和 as3 中的工作方式不同。把我的思绪拉回我as2的日子,当你设置这个回调函数时,你就在costGuideXML的范围内。由于您在此范围内,因此您无权访问 my_acc 变量。

您可能需要使用 Delegate 类来使 populateAccordian 方法在原始类的范围内执行(如果这是在时间轴上,则可能是动画片段)。

类似的东西(虽然这是未经测试的):

import mx.utils.Delegate;

    // Load Cost Guide feed.
    var costGuideUrl:String = "http://test/cost-guide.ashx";
    var costGuideXml:XML = new XML();
    costGuideXml.onLoad = Delegate.create(this, xmlLoadedHandler);
    costGuideXml.load(costGuideUrl);

    function xmlLoadedHandler() : Void
    {
     populateAccordian(costGuideXml); 
    }

    // Populate Accordian with retrieved XML.
    function populateAccordian(costGuideXml:XML) {

        var accordianPane = my_acc.createSegment("mcElectrical", "panel0", "Electrical", "payIcon");
        accordianPane.comboBox.addItem("test");
        // This line definitely executes...
    }

关于flash - 为什么我不能在 Flash CS4 的回调方法中访问组合框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/558639/

相关文章:

linux - Google Chrome/Chromium 在 Ubuntu 12.10 上有错误

java - 通过网站禁用屏幕保护程序/ sleep 模式

xml - 无法使用命名空间解析 flash 中的 XML AS3

flash - 用户上传文件上传时的实时RTMP流

加载外部数据时Flash CS4 IDE内部缓存

flash - 当已发布的电影具有 wmode ="transparent"时,MouseWheel 不起作用?

actionscript-3 - Actionscript 3.0 中的 MovieClip 与 Sprite

flash - ActionScript 2.0中的声音可视化

flash - 检查一个类是否有方法

actionscript-3 - 1084 : Syntax error: expecting rightbrace before dot