Titaniumにおいて、ImageViewでimages要素に画像の配列を与えることで、パラパラ漫画なアニメーションを実装できます。以下のような感じで。
var animationFrames = [ 'images/1.jpg','images/2.jpg','images/3.jpg','images/4.jpg' ]; var imageView = Ti.UI.createImageView({ images: animationFrames, duration: 100, repeatCount: 0, height: 200, width: 200, top: 30 }); Ti.UI.currentWindow.add(animationView); imageView.start();
ですが、上記実行時に以下のようなエラーが出ることがありました。
ERROR/TiUncaughtHandler(4242): (main) [22,1606] Sending event: exception on thread: main msg:java.lang.RuntimeException:
Unable to start activity ComponentInfo{xx.xxxxx.xxxxxx.xxxxxx/xx.xxxxx.xxxxxx.xxxxxx.XxxxxXxxxActivity}: java.lang.NullPointerException;
ERROR/TiUncaughtHandler(4242): java.lang.RuntimeException:
Unable to start activity ComponentInfo{xx.xxxxx.xxxxxx.xxxxxx/xx.xxxxx.xxxxxx.xxxxxx.XxxxxXxxxActivity}: java.lang.NullPointerException
NullPointerException ・・・まったく身に覚えがなく。。。
いろいろ探っていたのですが、どうやらImageViewのimagesがすべて読み込まれる前にstart()が実行されてしまい問題になるようでした。
というわけで、
imageView.addEventListener('load', function(e) { imageView.removeEventListener('load',arguments.callee); imageView.start(); .... });
というように、ImageViewのイベント「load」=画像が読み込まれたことを確認してから、start()するとうまくいくようです。
現状のTitaniumでは(Androidについては?)バッドノウハウがたくさん仕込まれることになりそうで、今後がちょっと心配ですが、、、俺の理解力の無さでしょうかね。