JohnnyBohnny
113 posts
|
I made a class for controlling my camera, which is imported on my main script (AS2). From that main script, I am able to call all functions inside the class. I copy-pasted a part of my script here:
class engine.camera
{
public function func1 ( Void ):Void
{
setPitch(0);
}
public function setPitch( newVal:Number):Void
{
//set pitch code
}
}
I get the error: There is no method with the name ‘setPitch’.
How can I call the function setPitch() inside the func1() function, without copying all the setPitch code?
|
|
|
UnknownGuardian
8131 posts
|
Are you sure class engine.camera shouldn’t be package engine.camera? I have no idea how stuff like this works in AS2 anymore, so just a guess. Or perhaps the classname isn’t allowed to have a . in it?
|
|
|
JohnnyBohnny
113 posts
|
Yes, I downloaded the Sandy3D engine (1.2) and started to modify it.
|
|
|
BobJanova
855 posts
|
AS2? this.setPitch(0), if I remember right.
Also, use AS3 ;-)
|
|
|
NineFiveThree
1370 posts
|
sandy3d with as2 =D
Do you think this function signature implies that there are no arguments?
public function func1 ( Void ):Void
Your code runs fine, without any errors.
How do you call that method?
|
|
|
Draco18s
6860 posts
|
The code you have posted should run just fine without error.
|
|
|
JohnnyBohnny
113 posts
|
Originally posted by BobJanova:
AS2? this.setPitch(0), if I remember right.
Doesn’t AS use this.* by default when it is not defined?
On my main (timeline) code:
import sandy.view.* //Camera3D class as shown in the first post
import sandy.primitives.*
//etc
function init(){
var cam:Camera3D = new Camera3D()
//…
cam.func1() //resets pitch
}
init()
I know there are workarounds, and currently I am using the Camera3D.lookAt(x,y,z) function, which uses its own coordinates with z+=1. I just think it’s odd.
E: Should I make the setPitch() function static?
|
|
|
NineFiveThree
1370 posts
|
Your class is named “camera”, in your code you use a class named “Camera3D”
Originally posted by JohnnyBohnny:
E: Should I make the setPitch() function static?
No.
You want to take a step back and take a look at the basics of how classes and packages work.
|
|
|
JohnnyBohnny
113 posts
|
That’s not the problem, I just simplified the code, the original Sandy3D code is 600 lines.
|
|
|
BobJanova
855 posts
|
Yeah you’re right this. shouldn’t be necessary. I remember some weirdness in this area but I think that is attaching functions directly to _root.
|
|
|
NineFiveThree
1370 posts
|
Originally posted by JohnnyBohnny:
That’s not the problem
It is the problem, because you’re modifying one class and using another or you were posting some unrelated code.
If you really want help, please post the actual code and its usage.
Originally posted by JohnnyBohnny:
I just simplified the code, the original Sandy3D code is 600 lines.
Why does the number of liens bother you?
Do you try to improve performance by deleting lines?
|
|
|
JohnnyBohnny
113 posts
|
The code that i posted is not the code that I’m using because it is 600 lines, and you don’t want to scroll through that. One of the things I changed was the class name.
Originally:
class sandy.view.Camera3D{}
But this isn’t helping me, 953
I’ll try some things tomorrow. I can use all private functions inside the class, but calling public functions within the same class isn’t working.
If you want the original code, download the sorces here=
I’m not sure if I’m allowed to post the entire thing here.
|
|
|
NineFiveThree
1370 posts
|
That’s not how one uses a library.
Either extend the existing Camera class or instantiate it in your class and manipulate the object.
You should not take one class and rip it apart, you should not change the name, because other things probably rely on that name.
If you want to add a method to the Camera3D class, extend it.
Again, try to figure out how to work with classes on a more basic level first.
|