|
-
Dance Monkey Dance!
Cant use extended classes variables or methods?
I have this problem from time to time with AS3 where I extend a Class and then try call methods and variables which are public from the new class but I get errors that method or variable doesn't exist. My IDE recognises the methods and variables though.
Heres an example
PHP Code:
//I have a base class
public class Box {
public var id:int;
public function somemethod() {}
}
//Then I extend the class
public class BiggerBox extends Box {}
//Then in a separate class I try this
var bigBox:BiggerBox = new BiggerBox();
trace(bigBox.id);
bigbox.somemethod();
When I run the script flash hates it. I thought when you extend a class it was supposed to inherit its properties and methods?
Does anyone else have these problems? I shouldn't have to cast it as Box. I swear I have this working in a project but cant see the different in setup?
"I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"
-
Senior Member
Where do you have the package in your classes? The code should otherwise work.
- The right of the People to create Flash movies shall not be infringed. -
-
Dance Monkey Dance!
Well, Box and BiggerBox both site inside the same package
package com.site.boxes {}
but the class calling the bigbox.somemethod(); is inside another package
package com.site.logic {}
"I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"
-
Dance Monkey Dance!
Actually I just searched and it was sort of a package problem.
The logic package already contained a class called bigbox and even though I imported com.site.boxes.BigBox;
The one in the package was overriding it.
Thanks for the help cancerinform. I appreciate it.
"I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"
-
Senior Member
Had to be something like that, because otherwise it would not have made sense.
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|