Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Custom Event not firing.


Gary Townsend
8/9/2006 8:19:17 PM
I am trying to load some data from an asp page that i wrote to to provie =
data to a flash order form. I am having a bit of a problem though that i =
want to load the list boxes from the asp data. Simple enough.=20

The problem i'm having is that i was trying to load the data but the =
LoadVars hadn't finished retrieving the data before the code moved on to =
try and load the data. SO I figured i needed to build an event for my =
data loader class that would fire once the data was loaded.=20

The problem is that my custom event isnt fire and i'm not really sure =
where i went wrong. The out put from my project is below as well as the =
code from the 2 files.

Output
initialize
Start Load
InLineSuccess: true
Data: Honda~Kawasaki~Yamaha~
event fired

OrderForm.fla
var dlPrintwerxMX:DataLoader =3D new DataLoader();
var loadListener:Object =3D new Object();
loadListener.onFinishLoad =3D function(){
trace("Event " + dlPrintwerxMX.MakeList);
}
dlPrintwerxMX.addEventListener("onFinishLoad",loadListener);
dlPrintwerxMX.LoadMake();

DataLoader.as
import mx.events.EventDispatcher;

class DataLoader{
private var strMake:String =3D new String();
private var strMakeID:String =3D new String();
//create a couple of methods to use in Flash
public var addEventListener:Function;
public var removeEventListener:Function;
//create the method to trigger the event
private var dispatchEvent:Function;

function DataLoader(){
trace("initialize");
EventDispatcher.initialize(this);
}
public function get MakeList():String{
return strMake;
}
=20
function LoadMake():Void{
trace("Start Load");
var lvLoader:LoadVars =3D new LoadVars();
var fLoadSuccess:Boolean =3D new Boolean();
lvLoader.onLoad =3D function(success){
trace("InLineSuccess: " + success);
if(success){
trace("Data: " + this.make);
strMake =3D this.make;
dispatchEvent({type:"onFinishLoad"});
trace("event fired");
}
fLoadSuccess =3D success;
}
lvLoader.load("http://HADES/printwerx/data.asp");
}
Gary Townsend
8/10/2006 5:14:11 PM
I have tried modifying the code to use callbacks rather than listeners. I've
traced the code through the debugger and the execution point passes over the
call to this.onFinishLoad however the call in the main flash file still
doesn't seem to trip.

OrderForm.fla

var dlPrintwerxMX:DataLoader = new DataLoader();

dlPrintwerxMX.onFinishLoad = function(){
trace("Event " + dlPrintwerxMX.MakeList);
}
dlPrintwerxMX.LoadMake();

DataLoader.as

class DataLoader{
//strings to hold the raw data
private var strMake:String = new String();
private var strMakeID:String = new String();
//create the data loader
public var lvLoader:LoadVars;
public var onFinishLoad:Function;

function DataLoader(){
//initialize the class
trace("initialize");
//initialize the data loader
lvLoader = new LoadVars();
//setup the callback for the loader.
lvLoader.onLoad = function(success){
trace("InLineSuccess: " + success);
if(success){
trace("Data: " + this.make);
strMake = this.make;
this.onFinishLoad();
trace("event fired");
}
}
}

public function get MakeList():String{
return strMake;
}

function LoadMake():Void{
trace("Start Load");
lvLoader.load("http://HADES/printwerx/data.asp");
}
}
-----------------------------
[quoted text, click to view]
I am trying to load some data from an asp page that i wrote to to provie
data to a flash order form. I am having a bit of a problem though that i
want to load the list boxes from the asp data. Simple enough.

The problem i'm having is that i was trying to load the data but the
LoadVars hadn't finished retrieving the data before the code moved on to try
and load the data. SO I figured i needed to build an event for my data
loader class that would fire once the data was loaded.

The problem is that my custom event isnt fire and i'm not really sure where
i went wrong. The out put from my project is below as well as the code from
the 2 files.


Gary Townsend
8/10/2006 8:22:16 PM
I think its my use of the key word this that is messing things up because
everything works as normal until i put the event call inside the LoadVars
objects .onLoad event. My question then is how can i reference the callback
for the main DATALOADER object without using the keyword this since my guess
is that this is actually referring to the LoadVars object.

[quoted text, click to view]

AddThis Social Bookmark Button