I tried to implement it like this but I don’t know from where he’s using that “.done” in a variable function, maybe it’s custom or java only but my questions are…
Do Haxe or OpenFL have something similar that could work like this and cross platform?
If so, can be used even with Actuate events (without relying on their ‘OnComplete’)?
If doesn’t, there’s any other basic workaround without timers?
Yes @T1mL3arn it must be the Static Extension, I didn’t know about it but looks really nice, there’s much to learn in Haxe
@hcwdikk in theory it’s the same and running thanks a lot, but that chain will run everything asap and my main goal is to do one function at a time without relying on Actuate or timers, more like dispatch events
var firstPromise = firstFunction();
firstPromise.done(/*...*/);
firstPromise isn’t a function, it’s a jQuery Promise object that was created and returned by firstFunction(). The Promise object is what implements the done() method.
Awesome thanks @player_03, I saw the imported JS libraries but thought it was using just Haxe syntax, looks very nice, do we have something similar and basic in Haxe or OpenFL?
Well, you could return an EventDispatcher object, and then listen for the COMPLETE event on that object.
Of course, you have to make sure the EventDispatcher actually dispatches the event at the right time. Loaders already do this, so you can just return the contentLoaderInfo object, but otherwise you’ll have to implement it yourself.
Yes I’ll have to try that, it should work with a combination of EventDispatcher and the use of OnComplete (when using Actuate) to trigger the ‘chained’ event.
Awesome, thanks a lot! you got the same concept and it’s great, i’ll check it out soon.
Let me show you what I had done, simple but was trying to achieve the same.
class SceneManager {
var collectedTasks = new Map<String, String->Void>();
var sceneList = new Map<String, Array<String>>();
public function new() { }
// Adding object functions
public function setUpObjects(taskName:String, task:String->Void):Void {
collectedTasks.set(taskName, task);
}
// Asociate Objects to Slides
public function setUpScene(sceneName:String, sceneItems:Array<String>):Void {
sceneList.set(sceneName, sceneItems);
}
// Execute functions
public function execFunctions(phase:String):Void {
for (k in collectedTasks.keys()) {
var newF = collectedTasks.get(k);
newF(phase);
}
}
// Slides transition
public function switchScene(current:String, next:String):Void { // Home to Page 1
var currentList:Array<String> = new Array<String>();
var nextList:Array<String> = new Array<String>();
var functionsCurrent:Array<Dynamic> = new Array<Dynamic>();
var functionsNext:Array<Dynamic> = new Array<Dynamic>();
currentList = sceneList.get(current);
// Actors parsed from Scene
for (i in 0 ... currentList.length) {
trace(currentList[i]);
functionsCurrent.push(collectedTasks.get(currentList[i]));
}
chain(functionsCurrent);
}
// Chain functions
private function chain(p_functions:Array<Dynamic>):Void {
var functions:Array<Dynamic> = p_functions.copy();
if (functions.length > 0) {
var firstFunction = functions.shift();
var firstPromise = firstFunction("fadeCurrent");
// Testing .done first
firstPromise.done(trace("ding!"));
}
}
)
I don’t understand all your code, because I don’t know the domain of your problem, but I think we are trying to solve the same problem.
I made that class because I was tired of messing up my classes with flags and ifs. The final code was always hard to understand and modify.
I use this class a lot and I think my code is 100% more clear and 1000% easier to experiment variations. Changing the behavior of an enemy is a peace of cake.
I use it specially in NPC or simple AI, but its also great for menu transitions. You just need to return true in your functions when the action is finish.
@juakob Yea sorry, it’s just a prototype and the chain purpose it’s mixed with another problem which I wanted to deal at the same time, managing ‘Scenes’ like switching pages or states like in a menu, where I would fade out or move away elements and then bring new ones. But like you say we are trying to address the same problem.
Awesome that’s the point, having a clear code where we can experiment with it without breaking anything lol, and focus on things that matters. Was looking at your blog and it’s very nice, I’ll keep an eye in it hoping you make more posts; also I’m from Mex, so if there’s way to contact you (aside twitter) in spanish would be great.
Thanks @singmajesty, taking a quick look it seems like my approach was more similar to your library than the @juakob lib.
Finally I’m seeing the light at the end of the tunnel, this has haunted me since the AS3 days of flash and quickly turned my work into spaghetti code rofl. I’ll try these libraries and surely gonna learn a lot, thanks for sharing them!
Btw this kind of post belongs to this category or should be in programming?