[Qt-qml] QML JS Weirdness
Petrus Lundqvist
petrus.lundqvist at nokia.com
Thu Dec 2 15:22:35 CET 2010
And not to nit-pick, but you don't even get the index of the property
but the "name" of the property, i.e. the name of the index. So the
result is a string rather than a number.
Generally you should never iterate arrays in JS using for (xx in yy),
which is for object property iteration. Instead you should use e.g.
Array.forEach. In your example that would be:
[textAnimation, eyeAnimation, eyeOutline,
pulseAnimation].forEach(function(animation) {
if (!value && animation.running) ...
});
Peppe
On Thu, 2010-12-02 at 15:15 +0100, ext Adriano Rezende wrote:
> 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
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
More information about the Qt-qml
mailing list