This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Ed Nepomuceno
Posted Aug 10 - Read on Facebook

Is there a way to attach html content to a state in the states machine?

7 Comments

Tisho Georgiev

You can use the Events.StateDidSwitch event to modify the html of a layer when switching to a new state.

myLayer.on(Events.StateDidSwitch, function(oldState, newState) {
if (newState === 'someState') {
myLayer.html = 'Content...'
}
})

Ed Nepomuceno

I can't get this to work for some reason. Does anyone have a live example I could look at? I'd appreciate it. Thanks in advance.

Tisho Georgiev

Ed, can you share the code you're trying out?

Tisho Georgiev

I just tested this out on my own, and the event handler has to be attached to layer.states, instead of just layer (Koen, we should probably change this). So the proper code is:

myLayer.states.on(Events.StateDidSwitch, function(oldState, newState) { ... });

Koen Bok

Yes I'll fix this

Ed Nepomuceno

Thanks, Tisho, Koen. That was exactly what I was missing. This would be a good, simple usage example to include in the documentation for Events.StateDidSwitch as well.

Chad Lonberger

Very helpful thanks

Read the entire post on Facebook