I have this code with which I am trying to load a spritesheet's associated JSON file...
class BunnyExample
{
Renderer renderer = new CanvasRenderer(width: 400, height: 300);
Stage stage = new Stage(new Colour.fromHtml('#ffffff'));
Graphics graph = new Graphics();
int drewLineCount = 0;
BunnyExample()
{
var assetsToLoad = ['sprites.json'];
// Create a new loader.
var loader = new AssetLoader(assetsToLoad);
// Use callback.
loader.onComplete.listen(onAssetsLoaded);
// Begin load.
loader.load();
stage.children.add(graph);
document.body.append(this.renderer.view);
}
void onAssetsLoaded(CustomEvent event) //Line 36 that stack trace references!
{
Sprite blah = new Sprite.fromFrame('wood_tile_2');
blah.position = new Point(0,0);
stage.children.add(blah);
}
However when I run it on pub serve I get this error trace
Exception: Uncaught Error: type 'String' is not a subtype of type 'CustomEvent' of 'event'.
Stack Trace:
#0 onAssetsLoaded (http://localhost:8080/pixitest.dart:36:35)
#1 _RootZone.runUnaryGuarded (dart:async/zone.dart:1089)
#2 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#3 _DelayedData.perform (dart:async/stream_impl.dart:595)
#4 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:711)
#5 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#6 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#7 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#8 _handleMutation (dart:html:40489)
I copied the general structure of the loading for this example...can someone tell me what I've done wrong? Thanks.
I assume you are using
https://github.com/emergent-design/pixi.dart
as you can see in the code athttps://github.com/emergent-design/pixi.dart
the onComplete stream will return strings and not a CustomEvent. So changingvoid onAssetsLoaded(CustomEvent event)
tovoid onAssetsLoaded(_)
should work.