How to use behavior inst.inst?

For developers using the Construct 2 Javascript SDK

Post » Thu Aug 07, 2014 8:03 pm

I'm writing a behavior that works with sprites. The behavior needs to access the sprite's curFrame object. In reading the docs, it seems the way to get to this is via inst.inst. However, when I try to access this.inst.inst, it says it is undefined. Can anyone tell me what I'm missing?

Thanks!
B
8
S
2
Posts: 55
Reputation: 616

Post » Thu Aug 07, 2014 10:48 pm

Try this.inst.curFrame instead.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Thu Aug 07, 2014 10:54 pm

blackhornet wrote:Try this.inst.curFrame instead.

Hah! I swear I tried that and it didn't work, except now it does. :) Thanks!

However, my original question still stands. In the event that it is needed, how does one use inst.inst?
B
8
S
2
Posts: 55
Reputation: 616

Post » Fri Aug 08, 2014 12:48 am

Do you get this.inst in on create function? It has not been created at that monument yet.
B
110
S
28
G
280
Posts: 4,487
Reputation: 156,566

Post » Fri Aug 08, 2014 2:03 am

@rexrainbox maybe try setTimeout(fn,0);

Example from pointerpos behavior where this.inst.elem isn't defined yet.
Code: Select all
   behinstProto.onCreate = function(){
      var self = this.inst;
      setTimeout(function(){
         self.elem['onselect'] = function(){ ... };
      },0);
   };
B
11
S
2
G
1
Posts: 202
Reputation: 1,580

Post » Fri Aug 08, 2014 12:12 pm

rexrainbow wrote:Do you get this.inst in on create function? It has not been created at that monument yet.

I've tried it several places, all outside of on create.

To reproduce:

  1. Copy a blank behavior from the SDK.
  2. In the sample action, add console.log(this.inst.inst);.
  3. Create a new project with a sprite with the behavior.
  4. Add a on touched object to call the sample action.
  5. Run the project, open the output console, and touch/click the sprite.
  6. Output is "undefined".
It seems like this might be a bug!
B
8
S
2
Posts: 55
Reputation: 616

Post » Fri Aug 08, 2014 12:54 pm

Ok, you might try to get it by expression of sprite, like that
http://c2plugins.blogspot.tw/2014/02/reuse-ace.html
B
110
S
28
G
280
Posts: 4,487
Reputation: 156,566


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests