Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
smartek
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook

ScaleTransition stopped/ended not working in javascript?

hi, i have a app which use some of the ScaleTransition like:

ScaleTransition {
	id: scaleBig
	duration: 1000
	fromX: 3.0
	fromY: 3.0
}

 

so i use

anim.play() 

 to run it, after it was stopped/ended i use something like:

anim.stopped(foo());

or

anim.ended(foo());

 

but in both cases, foo is executed directly after the animation is started not when it ends

Plase "+Like" my post if it was helpful.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: ScaleTransition stopped/ended not working in javascript?

Any time you evaluate "foo", you get a reference to the function. Any time you put () after a function reference, you call it.

Rather than anim.ended(foo()), I suspect you want just anim.ended(foo). The it's up to the anim.ended() routine to call foo for you. The way you did it, you're calling it right away, and basically doing this: var result = foo(); anim.ended(result);

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
smartek
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook

Re: ScaleTransition stopped/ended not working in javascript?

[ Edited ]

peter9477 wrote:
Any time you evaluate "foo", you get a reference to the function. Any time you put () after a function reference, you call it.

Rather than anim.ended(foo()), I suspect you want just anim.ended(foo). The it's up to the anim.ended() routine to call foo for you. The way you did it, you're calling it right away, and basically doing this: var result = foo(); anim.ended(result);

1. but how to do it, if the function foo has some parameters like: function foo(par1, par2) {...}

 

EDIT: 

2. i changed it now to anim.ended(foo), but now foo is never called. how to do it, that foo will be executed after the animation has ended?

Plase "+Like" my post if it was helpful.
Developer
smartek
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook

Re: ScaleTransition stopped/ended not working in javascript?

please, need to find a solution.

Plase "+Like" my post if it was helpful.
BlackBerry Development Advisor
IsaacGordezky
Posts: 57
Registered: ‎10-04-2012
My Device: developer

Re: ScaleTransition stopped/ended not working in javascript?

I think you are not using qml/javascript correctly.  Here is a little example I made to show you how to get signals from an animation so you can execute your code when an animation stops.

 

import bb.cascades 1.0
 
Page {
    content: Container {
        layout: DockLayout {
        }
        Button {
            id: scaleButton
            text: "Click me"
             
            animations: [
                ScaleTransition {
                    id: scaleAnimation
                    fromX: 1.0
                    toX: 2.0
                    duration: 3000
                    
                    onStopped: {
                        console.log("scaleAnimation.onStopped")
                    }
                    
                    onEnded: {
                        console.log("scaleAnimation.onEnded")
                        // reset button to initial state
                        scaleButton.scaleX = scaleAnimation.fromX
                    }
                }
            ]
             
            onClicked: {
                if (scaleAnimation.state == AnimationState.Stopped
                    || scaleAnimation.state == AnimationState.Ended) {
                    scaleAnimation.play()
                    console.log("scaleAnimation.play")
                } else {
                    scaleAnimation.stop("scaleAnimation.play")
                }
            }
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
        }
    }
}

 

If this helps you, please mark it as a solution.

Developer
smartek
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook

Re: ScaleTransition stopped/ended not working in javascript?

sorry this does not help me to fix this issue in javascript

Plase "+Like" my post if it was helpful.
Developer
smartek
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook

Re: ScaleTransition stopped/ended not working in javascript?

The key is:

 

I can not call a function when I'm using animationName.ended(myFunction) in JavaScript

Plase "+Like" my post if it was helpful.