Why can't I access combobox in the callback method in Flash CS4?

Check this code:

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

This adds an item labeled β€œtest” to the combo box in the movie clip. It works great. However, when I put the same code in a callback function, it fails.

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...
}

Any ideas on why I can't get into the combo box inside the callback?

+3
source share
1 answer

Ok, so at first it seems like you are using AS2.

2, , , . - 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...
    }
+2

Source: https://habr.com/ru/post/1703372/


All Articles