[Qt-qml] QML JS Weirdness
Adriano Rezende
adriano.rezende at openbossa.org
Thu Dec 2 15:15:44 CET 2010
On Thu, Nov 18, 2010 at 9:44 PM, Jason H <scorp1us at yahoo.com> wrote:
> The following does not work. However is I replace the animationSet function
> with individual lines of {animation}.running = {value} then it works.
> Also please the comment points out an annoyance.
>
> Can anyone tell me if I am wong, or if QML is wrong.
> Qt 4.7.0
>
> function animationSet(animations,value)
> {
> for (var animation in [textAnimation, eyeAnimation, eyeOutline,
> pulseAnimation])
> {
> if (value == false && animation.running == true)
> // animations, when running== false and re-set to false
> { // will emit Completed !?!1
> animation.running = false;
> } else {
> animation.running = true;
> }
> }
> }
> function start() {
> stop();
> root.visible=true;
> animationSet([textAnimation, eyeAnimation, eyeOutline, pulseAnimation,
> mainAnimation], true);
> console.log("start called for "+ name);
> }
>
Hi,
Using for-in statement, you will get the index of the object, not the
object itself.
Also, instead of iterating over the items using javascript, it's
better use property bindings to improve performance. Just remove
animationSet method and bind the "running" properties to a root
property, like this:
Item {
id: root
property bool active : false
NumberAnimation { id: textAnimation; running: root.active; ... }
NumberAnimation { id: eyeAnimation; running: root.active; ... }
// ...
function start() {
stop();
root.visible = true;
root.active = true;
}
}
Br,
Adriano
More information about the Qt-qml
mailing list