Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire callback when fifteen puzzle has been completed #41

Closed
zeorin opened this issue Jun 4, 2012 · 1 comment
Closed

Fire callback when fifteen puzzle has been completed #41

zeorin opened this issue Jun 4, 2012 · 1 comment

Comments

@zeorin
Copy link

zeorin commented Jun 4, 2012

Hi, I'm very new to libcanvas and canvas in general. I would like to fire a callback event when the fifteen puzzle (from your examples) has been completed. How should I go about doing that?

I wouldn't normally create an issue for a question but I have been unable to find another way to contact you.

@theshock
Copy link
Owner

theshock commented Jun 4, 2012

Hi!

We should Implements Events mixin in Fifteen controller:

Fifteen.Field = atom.Class({
    Extends: atom.Class.Options,
    Implements: [ atom.Class.Events ],
    initialize: function (options) {

So now we can fire events of field and we can do it:

activate: function ( disableAll ) {
    if (this.isComplete()) {
        return this.fireEvent( 'complete' );
    }
    // ...
},

Than we can bind for events in controller instance:

atom.dom(function () {
    var fifteenField = new Fifteen.Field({
        tile: {
            width : 64,
            height: 64,
            margin: 4
        }
    });

    fifteenField.addEvent( 'complete', function () {
        alert( 'WIN!' );
    });
});

If you have any questions - you can write me to skype: shock13666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants