I started new project from scratch on dart lang and was faced with a problem calling method of polymer element instance.
For example I have fps-counter element (fpsCounter.dart):
@HtmlImport('fps_counter.html')
library fpsCounter;
import 'package:web_components/web_components.dart' show HtmlImport;
import "package:polymer/polymer.dart";
import "dart:html";
@CustomTag("fps-counter")
class FpsCounter extends PolymerElement
{
@observable
int fps;
// counter that will cleared at 60 ticks
int _counter = 0;
// accumulator delta time for 60 ticks
int _accumulator = 0;
factory FpsCounter() => new Element.tag('fps-counter');
FpsCounter.created() : super.created() {
polymerCreated();
}
bool calculateFps(double delta)
{
if (_counter == 60)
{
fps = (60000 / _accumulator).round();
_counter = 0;
_accumulator = 0;
print("$fps FPS");
return true;
}
_accumulator += delta;
_counter++;
return false;
}
}
And want to invoke calculateFps(0.016)
from out as in example below:
void _initRenderer(OSE ose)
{
FpsCounter fpsCounter = new FpsCounter();
fpsCounter.calculateFps(0.016);
document.body.children.add(fpsCounter);
}
But faced with problem:
Exception: Uncaught Error: Class 'HtmlElement' has no instance method 'calculateFps'.
I really do not wanna create additional communication around that, any ideas how to make it better or how to invoke method? Thanks.
Also please to see additional files that can help:
pubspec.yaml
name: os
version: 0.0.1
dependencies:
browser: ">=0.10.0 <0.11.0"
ose:
path: ./libs/ose
polymer: any
transformers:
- polymer
fps-counter.html
<link rel="import" href="packages/polymer/polymer.html" />
<polymer-element name="fps-counter">
<template>
<div>
{{fps}} FPS
</div>
</template>
<script type="application/dart" src="fpsCounter.dart"></script>
</polymer-element>