Accessing Mesh in MeshFilter Component Problems

Hi, any ideas would be greatly appreciated!
This is actually my first post.

I have constructed a dynamic system for Mesh generation that works fine in the editor,
and now, as I want to build and view it on an iPhone device, it shows a compiler error, when building:

Assets/Scripts/Generator.js(31,57): BCE0019: ‘mesh’ is not a member of ‘UnityEngine.Component’.

gameObject.AddComponent(MeshFilter);
gameObject.AddComponent("MeshRenderer");
	
renderer.material = material;

var planeMesh : Mesh = GetComponent(MeshFilter).mesh;

I tried to add “as Mesh” in the end of the variable declaration line,
which works also only in the editor.

Thanks for any advice. I will try to find a solution myself in the meantime,
and post it back here if I find it.

Alright folks, I have been on something else until now and I came back to this issue and found out what to do to make the errors go away :wink:

Simply access the mesh trough one more buffer variable (so the GetComponent is not in the same line)

var meshComponent : MeshFilter = GetComponent(MeshFilter);
	
var mesh : Mesh = meshComponent.mesh;

Simples!