• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Canvas: Javascript to stop() a Movieclip not working

New Here ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

Dear Community,

the following behavior is not clear to me. Can you please explain the following to me. Please look at this example:

(lib.ClickWidget = function(mode,startPosition,loop) {

    this.initialize(mode,startPosition,loop,{});

    // timeline functions:

    this.frame_0 = function() {

        //does not work

        this.f_interactionButtonBackground.stop();

       

        //does work

        self = this

        setTimeout(function(){ self.f_interactionButtonBackground.stop(); }, 1);

    }

    // actions tween:

    this.timeline.addTween(cjs.Tween.get(this).call(this.frame_0).wait(1));

    // Layer 3

    this.f_interactionButtonBackground = new lib.interactionButtonBackground();

    this.f_interactionButtonBackground.parent = this;

    this.f_interactionButtonBackground.setTransform(0,0.8);

    this.timeline.addTween(cjs.Tween.get(this.f_interactionButtonBackground).wait(1));

}).prototype = getMCSymbolPrototype(lib.ClickWidget, new cjs.Rect

angle(-91,-11.7,261.1,100.7), nul

Please compare line 7 and 11. Code in Line 7 does not work but code in line 11 does work. I see that the call to stop() does not result in an error so this.f_interactionButtonBackground does resolve.

What I can imagine is that stop is actually called but just because of some reason only later the move clip will start and the stop is irrelevant calling it before the movieclip actually started. Now adding 1 millisecond it gives enough time so the this.f_interactionButtonBackground started playing and stop is actually stopping it.

Can somebody please say what is happening, because I am afraid that why I am doing is not the right way and not a robust way to solve the problem.

Thanks

Views

394

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 16, 2017 Aug 16, 2017

At the time that line 7 runs the movieclip f_interactionButtonBackground isn't yet intialized, and so after you have told it to stop(), it then tells itself to play(). The initializing within the movieclip doesn't know that you had tried to stop it.

The setTimeout works around that, it runs as soon as it can, and that is already after f_interactionButtonBackground has initialized, and so the trick works.

A safer solution might be to put this into f_interactionButtonBackground's timeline's first fr

...

Votes

Translate

Translate
LEGEND ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

LATEST

At the time that line 7 runs the movieclip f_interactionButtonBackground isn't yet intialized, and so after you have told it to stop(), it then tells itself to play(). The initializing within the movieclip doesn't know that you had tried to stop it.

The setTimeout works around that, it runs as soon as it can, and that is already after f_interactionButtonBackground has initialized, and so the trick works.

A safer solution might be to put this into f_interactionButtonBackground's timeline's first frame:

this.stop();

then it will stop itself immediately.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines