PDA

View Full Version : oncall function won't call another function within a class


legster
11-04-2005, 01:41 PM
I am trying to call another function to load data and build the application, but only after the xml data is loaded. I can't seem to call another function from within the onload function. This worked fine outside of a class, but when I move it into the class it no longer works. Below is the sample code. Thanks for any help.

dynamic class testProject {

function testProject() {
keywords_xml = new XML();
keywords_xml.load("test.xml");
keywords_xml.onLoad = keyLoad;
keywords_xml.ignoreWhite = true;
}

function keyLoad():Void {
trace('test1');
loadData()
}

function loadData():Void {
trace('Can't seem to get here');
}
}

hangalot
11-04-2005, 02:30 PM
firstoff why do you declare your class as dynamic, i see no reason EVER to do this, its just bad practise. look into mx.utils.Delegate with scoping issues. you can do this.


import mx.utils.Delegate;
class testProject {
private var keywords_xml:XML;
function testProject() {
keywords_xml = new XML();
keywords_xml.load("test.xml");
keywords_xml.onLoad = Delegate.create(this,keyLoad);
keywords_xml.ignoreWhite = true;
}

function keyLoad():Void {
trace('test1');
loadData()
}

function loadData():Void {
trace('Can't seem to get here');
}
}

Xeef
11-04-2005, 02:42 PM
hi andwelcome to As.Org

try :


keywords_xml.onLoad = mx.utils.Delegate.create(this,keyLoad)

legster
11-04-2005, 06:23 PM
Thank you for the help. Declaring the class as dynamic was the only way to make a dynamic movie duplication script work that was already in place. So making it dynamic was just an easy fix.

I have 7.0 which does not have the Delegate class. I need to upgrade to 7.2, since I tried running it through there and it worked. Thanks!