Switch Layer Problem

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Switch Layer Problem

Post by dkwroot »

MY GOAL:
I would like the user to be able to draw on a switch layer and have whatever they draw get placed on frame 0 of the currently active sub-layer. This will allow users to easily do FBF animations in a form similar to flash and other FBF programs.

THE PROBLEM:
When the switch layer is selected, I first find the name of the active layer. Then I do a 'for loop' and look for a sub-layer that matches the name. This gives me the MohoLayer of my sub-layer. I executed the function MohoLayer:LayerType() and got 1, which means it's a vector layer. The problem is that when I try to access the mesh for this vector layer, the program always tells me that the Mesh() function is nil.

Now correct me if I'm wrong, but "Vector Layers" are the same as "MeshLayer", right? If you check the API for MeshLayer, you'll see the function "Mesh()", but the programs seems to be ignoring this ... any ideas?

LINK TO MESH LAYER API: http://aslua.com/index.php?show=class&name=MeshLayer
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Re: Switch Layer Problem

Post by dkwroot »

YES! Figured it out.

It turns out that the MohoLayer you get from the ":Layer(id)" function is a generic MohoLayer. You then have to cast it to the vector type using LayerAsVector(layer).

Sweeeeeeeeeeeeet~
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Re: Switch Layer Problem

Post by dkwroot »

NEW PROBLEM:
I can now draw on a child layer from the parent switch layer. The problem that I'm having is that I can't create a shape for a child layer from the parent. It seems that the createshape function is localized to moho, which is strictly the currently selected layer.

I did see that LM_MeshPreview has a createshape function, but I don't know anything about it. I'm not even sure how to define a variable as an object of the MeshPreview class. Any ideas?

LINK: http://aslua.com/index.php?show=class&n ... eshPreview
User avatar
synthsin75
Posts: 10271
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Layer Problem

Post by synthsin75 »

MeshPreview is used by things like the Star menu script. It gives a preview of the shape from the dialog.

I would suggest selecting the sublayer briefly to create the shape (you should be able to do this fast enough that the user hardly notices).
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Re: Switch Layer Problem

Post by dkwroot »

synthsin75 wrote:MeshPreview is used by things like the Star menu script. It gives a preview of the shape from the dialog.

I would suggest selecting the sublayer briefly to create the shape (you should be able to do this fast enough that the user hardly notices).
This was my original plan, but I was worried that it would cause the screen to flicker a little or the switch layer would rapidly expand and collapse every time the user draws. Thankfully this doesn't happen at all! The developers chose not to auto-update the UI when you switch layers in code, which is wonderful.
User avatar
synthsin75
Posts: 10271
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Layer Problem

Post by synthsin75 »

Yeah, showing the layer selected by a script is optional. I have even gotten away with showing a different layer's timeline, although I don't remember how well it works now days.
Post Reply