summaryrefslogtreecommitdiffstats
path: root/examples/declarative/dynamic/dynamic.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/dynamic/dynamic.js')
-rw-r--r--examples/declarative/dynamic/dynamic.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/declarative/dynamic/dynamic.js b/examples/declarative/dynamic/dynamic.js
new file mode 100644
index 0000000..66ec292
--- /dev/null
+++ b/examples/declarative/dynamic/dynamic.js
@@ -0,0 +1,52 @@
+var sprite = null;
+var component;
+var started = false;
+function make(p) {
+ return evalQml('Rect { color: "lightsteelblue"; width: 100;'
+ + 'height: 100; id: newRect}','DynPart.qml');
+}
+
+function death() {
+ if(!(sprite==null)){
+ sprite.destroy();
+ sprite = null;
+ }
+}
+
+function spawn() {//Like create, but assumes instant readyness
+ if(sprite!=null)//Already made
+ return null;
+ component = createComponent("dynamic.qml");
+ sprite = component.createObject();
+ if(sprite == null){
+ print("err");
+ }else{
+ sprite.parent = targetItem;
+ return sprite;
+ }
+ return null;
+}
+
+function finishCreation(){
+ if(component.isReady()){
+ sprite = component.createObject();
+ sprite.parent = targetItem;
+ }else if(component.isError()){
+ sprite = null;
+ }
+}
+
+function create(){
+ if(started!=false){
+ finishCreation();//Remakes if destroyed
+ return sprite;
+ }
+ started = true;
+ component = createComponent("dynamic.qml");
+ finishCreation();
+ if(sprite != null){
+ return sprite;
+ }
+ component.statusChanged.connect(finishCreation);
+ return null;
+}