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

What is Framer? Join the Community
Return to index
Shane Brown
Posted Dec 22 - Read on Facebook

I'm a bit of a coffeescript noob (and fairly fresh with JS too). Would someone be able to help me understand an error I've been getting?

I've got an array holding Layer objects, and while checking a Touch Event on the bg layer, I want to trigger the shadows based on mouse position (just playing off one of the examples) and to do this I need to get the midX and midY values from the Layer objects. When I do this within a touch event though it gives me an error stating that "undefined is not an object".

I've uploaded the .framer here >

and the plain code is here with comments


Benjamin Den Boer

Hey Shane Brown,

Thanks for attaching a .framer file! Let's see. So, first, you've defined and created 3 layers within an array called boxArray. You assign each layer a unique number using the "num" as the value representing each array index value.

The range you've defined is [0..2] - so you create three layers: boxArray0, boxArray1 and boxArray3 - all within the boxArray array.

Now when you create a new loop within your TouchMove event - you define a new range from [0..3] - and try to target an additional layer: "boxArray4" - which doesn't exist. The simplest fix with your current code would be simply to change the [0..3] to [0..2].

But, an additional note: since you've created these layers within an array, you need not really create loops with new variables each time you'd like to target items within your array. So, an alternative way to target each layer would be like this: (replacing boxArray[i] with "layers" - or any other name you'd like - which you can also use when switching states within your TouchStart event)

Here is a framer link to your prototype with the edits I've described above:

Shane Brown

Thanks Benjamin. I did try something similar but it didn't end up working at the time for whatever reason. Looks like I might of been making a bunch of tired mistakes a long the way!

Read the entire post on Facebook