Studi Kasus Loading File FXZ


Kasus dibawah ini adalah contoh ketika saya mencoba me-load file .fxz kemudian ingin mengambil atau memunculkan salah satu Node/ImageView dalam paket .fxz/group tersebut dan memanipulasinya. Dibawah ini contoh kodenya:

……….

var stage:Stage =   Stage {
title: “HTI Channel Player”
width: 400
height: 200
style:StageStyle.TRANSPARENT
};
var scene:Scene=Scene{};

public function run() {
var fxd = FXDLoader.loadContent(“{__DIR__}skins/BaseSkin.fxz”);
var play2=fxd.getNode(“play”);
var fxdContent = FXDLoader.loadContent(“{__DIR__}skins/BaseSkin.fxz”);

//——— isi paket dari file .fxz tersebut diinisialisasi pada group
var group=fxdContent.getRoot();
//———– mengambil node/image pertama pada group

var play = group.content[0];

//———- kemudian image/node tersebut saya coba masukan kedalam scene.content
insert play into scene.content;
play.translateX = 100;
}

stage.scene=scene;
stage;

}

//———— ketika kode ini dijalankan

Akan muncul error seperti ini:

WARNING * WARNING * WARNING * WARNING * WARNING
An attempt has been made to add node to a new group without
first removing it from its current group. See the class
documentation for javafx.scene.Node for further information.
This request will be granted temporarily but it will
be refused in the future. Please change your code now.
node=ImageView oldgroup=Group newgroup=Group
Stack trace follows.
java.lang.IllegalArgumentException
at javafx.scene.Group$_SBECL.onChange(Group.fx:162)
at com.sun.javafx.runtime.location.SequenceVariable.notifyListeners(SequenceVariable.java:157)
at com.sun.javafx.runtime.location.SequenceVariable.setAsSequence(SequenceVariable.java:259)
at com.sun.javafx.runtime.location.SequenceVariable.set(SequenceVariable.java:222)
at com.sun.javafx.runtime.location.SequenceVariable.set(SequenceVariable.java:39)
at com.sun.javafx.runtime.location.Bindings$BijectiveBinding$2.onChange(Bindings.java:151)
at com.sun.javafx.runtime.location.AbstractLocation$1.onAction(AbstractLocation.java:219)
at com.sun.javafx.runtime.location.AbstractLocation$1.onAction(AbstractLocation.java:216)
at com.sun.javafx.runtime.location.AbstractLocation.iterateChildren(AbstractLocation.java:181)
at com.sun.javafx.runtime.location.AbstractLocation.invalidateDependencies(AbstractLocation.java:253)
at com.sun.javafx.runtime.location.SequenceVariable.notifyListeners(SequenceVariable.java:150)
at com.sun.javafx.runtime.location.SequenceVariable.replaceSlice(SequenceVariable.java:324)
at com.sun.javafx.runtime.location.SequenceVariable.insert(SequenceVariable.java:442)
at player.Main.javafx$run$(Main.fx:81)
at player.Main.javafx$run$(Main.fx:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.runtime.provider.GUIRuntimeProvider$1.run(GUIRuntimeProvider.java:65)
at com.sun.javafx.tk.swing.SwingToolkit$StartupRoutine.run(SwingToolkit.fx:593)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Hasilnya tetap muncul image/node yang diinginkan, tapi tetap muncul error diatas. Hal ini karena ternyata saya mencoba menambahkan node yang ada di group A (misalkan) ke dalam group B (misalkan) tanpa menghapus terlebih dahulu node tersebut di group A.

Jadi solusinya (1) tetap sesuaikan dengan dokumentasi pada API JavaFX, yaitu load/masukan keseluruhan isi group tersebut pada scene.content, baru setelah itu ambil node tertentu kemudian manipulasi deh. Atau (2) bisa saja dengan mengikuti peringatan dari compiler tadi yaitu dengan menghapus dari group pertama kemudian tambahkan pada group baru. Tapi tentu berarti node tersebut akan hilag di group pertama. klo mo caba silahkan.

Tapi untuk solusi (1) akhirnya saya coba tambahkan kode berikut:

//——– masukan/load group tersebut kedalam scene.content

insert group into scene.content;

//——– baru ambil node tertentu

var play = group.content[0];

//———- nah sekarang aman untuk bisa di manipulasi
play.translateX = 100;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: