I've been trying to make a mod for Scratch that would use the website's API to pull information about user's. The problem is that I've had to break it into two blocks. (These blocks work by calling functions based on a table with block names and function names, and passes in the arguments.) I've set it up where the first one (which calls primAskAboutMe) loads the information from the API, and then when the information loads, the user can use the second block (which calls primReportAboutMe) to return the value. The problem is that I can't get the second block to return an answer.
So either I'm trying to get information the wrong way, (which is possible because this is the first time I've used Action Script/Flash or whatever,) or I really don't understand what I'm doing.
*Note: Original Scratch Repository. This code would be found in src/primitives/Primitives.as (but isn't because I haven't uploaded this yet to my own repository, because I'm not really sure how).
protected var resultAM:String;
protected function primAskAboutMe(b:Block):void {
var user:String = interp.arg(b, 0);
var loader:Loader = new Loader();
var url:String = 'http://www.api.scratch.mit.edu/users/'+user;
var urlReq:URLRequest = new URLRequest(url);
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onCompleteAboutMe );
loader.load(urlReq);
}
protected function onCompleteAboutMe(e:Event):void{
//resultAM = e.target.data;
resultAM="foo";
}
protected function primReportAboutMe():String{
return resultAM;
}