Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Multiple Inheritance.



I am building a custom component but I want to use properties from two classes. I have extended one but how can I use the properties from the second? Create and instance of the second in my custom class? If yes how will the custom class use these properties? Thank you.



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 04-18-2008, 11:13 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Multiple Inheritance
I am looking for an example that will show me how to work around the no-multiple-inheritance problems in AS2. I have a class that extends the UIComponent, but I also want to extend the XMLSocket. I've looked and looekd and see no good example for when I'm writing my class.

[AS3] Multiple Inheritance
Without being able to modify the prototype chain, is it possible to fake multiple inheritance in AS3?

Say I have three Window classes. One is a DraggableWindow, one is a ScalingWindow, and one is a BorderWindow.

I want to mix and match new subclasses at runtime without having to make tons of new permutations of Window subclass possibilities.

Sure, I can implement these behaviors of the Window class as interfaces, but I would still have to account for all the permutations of interface combinations.

Does anyone have an elegant solution to this? I looked at the Decorator pattern, but seems like that is only applicable when you want to add new functionality to existing methods.

Multiple Inheritance
I am looking for an example that will show me how to work around the no-multiple-inheritance problems in AS2. I have a class that extends the UIComponent, but I also want to extend the XMLSocket. I've looked and looekd and see no good example for when I'm writing my class.

Inheritance In AS3
Does anyone know how to find out if a class is a DisplayObject without instantiating it? I am passing a class in to a method within another class and I need to run a check to see if it is a DisplayObject.

Thanks!

Inheritance Bug
this is what I consider a serious bug in the inheritance functionality of as3 (esp. considering that as2 would execute equivalent code correctly):









Attach Code

package {
public class A {
private const MYCONST:String = "A";
public function A(){}
public function toString(){ return this.MYCONST; }
}
}

package {
public class B extends A {
private const MYCONST:String = "B";
}
}

trace( new A() ); // prints "A";
trace( new B() ); // prints "A" ?!?!?!?!??!

OOP Inheritance
Greetings. It's been a while, but I've been caught up in all sorts of things. How've you been? How're the kids?

I'm subclassing DisplayObject (not directly), but I'm doing it in an interesting way, and I want to override some of the properties of DisplayObject, or remove them altogether. For instance, the rotation property of DisplayObject is relatively worthless in my new class, but there is another public property of my class very similar to rotation that I'd really, really like to call rotation. Is this at all possible?

Inheritance
Apologise if this is very simple:

I've got a Flash document with a base class set as "Base". Within Base.as, I then create an instance of a class called "DrawingApp". Within DrawingApp.as, I get this error:


Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DrawingApp/::init()
at DrawingApp$iinit()
at Base/::init()
at Base$iinit()
So, I have a look, and it appears to be "stage" that's causing this issue because within DrawingApp.as, I've got stage.addEventListener(MouseEvent.MOUSE_DOWN,someF unc);

So, if I remove the stage. part, the script doesn't work. Can someone just quickly explain this sort of inheritance and targeting for me please?

[as1][help]inheritance
[confession] have also posted this in penners book forum but need answer fast[/confession]

Right basically, in making a game I have a load of NPC's with similar properties(health, ac) and methods(attack, defend etc) and want to make a basic NPC class and then use inheritance to tack on other properties and methods on specific NPC classes, the problem is... I don't have a clue on how to do it and make it work

I've re-read penners bit on SuperCon a dozen times and cannot make it happen on my PC. Does anyone know how to do it successfully or maybe have a very small working fla, I literally need the code so that I can transfer both methods and properties from one class to another and then append if required

cheers

Zen

Inheritance
I want to ask if it is possible to have superclass (class inheritance) in Actionscript, something like this (as in Java):

class MyClass extends ParentClass {
MyClass() {
super(xyz);
}
}

does anyone know?

Inheritance Problem...
--------------------------------
bicycle=function(year,color,wheel,price,speed){
this.year=year;
this.color=color;
this.wheel=wheel;
this.price=price;
this.speed=speed;
}

bicycle.prototype.info=function(){
trace("my prodused by"+this.year );
trace("my color is"+this.color);
trace("i have "+this.wheel+ " wheels" );
trace("my price is "+this.price);
trace("my speed is "+this.speed);

}

subBicycle=function(year,color,wheel,price,speed,w eight){
this.__proto__=new bicycle(year,color,wheel,price,speed);
this.weight=weight;
}

subBicycle.prototype.info=function(){
trace("my weight is "+this.weight);
}

b1=new subBicycle("1","green",3,33,333,3000);
b1.info();
--------------------------------
in the code above,i can't trace the property "weight" of the subBicycle,why?could anyone tell me?thanks~

Q: Object Inheritance
Just wondering, if you are using object inheritance, does the "class extension" have to come before the constructor, e.g.:


Code:
// Foo inherits from Bar:
Foo.prototype = new Bar();

// Foo constructor:
function Foo() {
...
}

Foo.prototype.someFunction = function(x) {
...
}

//// This doesn't seem to work if I put it here:
// Foo.prototype = new Bar();

//// But this does:
// Foo.prototype.__proto__ = new Bar();
Because I tried it the other way and it doesn't work.

Actually it makes sense now that I think about it. Anyone have an opinion about setting __proto__?

Prototypes And Inheritance
Hi,

Is it possible to change a Textfield's inheritance (properties) to inherit MovieClip properties? I've tried this but no luck:


Code:
Object.TextField.__proto__ = MovieClip.prototype;

or

Code:
TextField.__proto__ = MovieClip.prototype;

(MX) Inheritance Question
while supposedly it is possible to have a class inherit the methods and properties from other classes.
For MovieClips this is only possible with an 'Object.registerClass ' (right? ) my question is: Is there an actionScript trick to make movieClips inherit from different classes, like registering selectively and therefore choose the methods / properties you want on each MC? i'd guess you have to combine the classes into Subclasses or something and then have MCs inherit from those... although you should be very aware of the possible combinations you may need...
etc

Inheritance Issues
I'm using the FS-SpecialMenu (http://www.flashkit.com/movies/Inter...4565/index.php) which I modified to contain links and buttons. The problem is, and for the life of me I can't figure out why, is that each new instance I create of the menu inherits the traits of the old menu. Not only that, any change in either menu creates a duplicate change in the other menu. What this means is changing the button's behaviors in one menu instance creates the same change in the other menu(s). This creates real problems because I need the buttons to point to different links in each menu.

Here is the source file: http://www.foundmyself.com/menu.fla

All help is awesome and really appreciated. Thanks a lot.

-trevor

Please Help W/ Inheritance Properties
can someone please explain to me in great detail the significant difference between:

.prototype and ._proto_?

thanks in advance.

Inheritance Problem With 2 Swf's
I have a main swf file which has a container movieclip that all my seperate swf's are loaded into.

My button calls to change a movieclip's textbox in my external swf is:

_root.movieclip.loadVariables("http:call to database");

And it works fine when I test it by itself.

But the external swf is loaded into the container movieclip of the main swf, the button calls arent working.

I believe this is happening because my _root variable has changed, but I dont know how to fix the problem I am having. Can anyone help.

Inheritance Problem With 2 Swf's
I have a main swf file which has a container movieclip that all my seperate swf's are loaded into.

My button calls to change a movieclip's textbox in my external swf is:

_root.movieclip.loadVariables("http:call to database");

And it works fine when I test it by itself.

But the external swf is loaded into the container movieclip of the main swf, the button calls arent working.

I believe this is happening because my _root variable has changed, but I dont know how to fix the problem I am having. Can anyone help.

Inheritance Problem AS2.0
Hello,

Could anybody tell me why the following code doesn't work?

code:
// in A.as
class A {
public static var p:String = "hello there";

public static function m():Void {
trace(A.p);
}
}

// in B.as
class B extends A {
}

//in fla
B.m();


when I use A.m() in the fla I get what I want: hello there.

But for some reason I can't reach the class property of B's superclass the way mentioned and I can't see why not.
It seems like B doesn't inherit the class methods of A. If I create instance methods in A and evoke them through an instance of B everything is going fine.

Hope someone can explain what's happening.

Thnx,
Jorrit

BTW., this example is coming out of Moock's AS 2.0 book.

Class Inheritance
Hi,

I'm having some trouble putting theory into practice in regards to Class inheritance. I want to create a Class of enemy that can be used to create individual enemy objects. I would like to use the attachMovie method to attach the necessary graphics to the newly created objects, but I can't seem to get it that code to fire inside a function. Here is what I have tested...
code:
//Create a Class
function Enemy(x, y, hp) {
this.attachMovie("bat","bat",10);
this._x = x;
this._y = y;
this.health = hp;
}
//Create a new enemy object from the enemy "Class"
badGuy = new Enemy(200, 100, 100);
trace("badGuy _x = "+badGuy._x+"
"+"badGuy _y = "+badGuy._y+"
"+"The new bad guys health points are "+badGuy.health);



The linkage is set correctly from for the needed clip in the library. The clip attaches correctly if called from the main timeline and not the created Class. Any suggestions as to what I am missing?

Thanks in advance
NTD

Flash Inheritance
Relative Paths
From mc1 to Root its: _parent.functionName
From mc1 to mc2 its: _parent.mc2.functionName
From a to mc2 its: _parent._parent.mct.functionName
From a to b its: _parent.b.functionName

Absolute Paths
From mc1 to Root its: _root.functionName
from mc1 to mc2 its: _root.mc2.functionName
from a to mc2 its: _root.mc2.functionName
from a to b its: _root.mc1.b.functionName

Absolute paths are not recommended due to the fact that they change when the movie is loaded into another. In cases where you are not comfortable with relative paths, you can do this:
On the root timeline, place something like this:
myRoot = this;
Then, anywhere in your movie where you would put _root.something place myRoot.something

Inheritance Question...
In the flash docs.. the Screen class says:


Code:
The Screen class has two primary subclasses: Slide and Form.
But in the Form class the docs mention:


Code:
Because the Form class extends the Loader class
But we all know AS doesnt support multiple inheritance..so whats the true answer? lol

Basic Inheritance
Hi

I'm just starting to look at AS3 and have come across a stumbling block.
Can anyone explain to me why I can't target a movieclip when I extend a class. For example I have a clip called 'test_mc' in a movieclip with a class of TestClass.
This works:

PHP Code:




package{
    import flash.display.MovieClip;
    public class TestClass extends MovieClip{
        public function TestClass(){
            trace(test_mc.x)
        }
    }
}






If I then extend this class and set the linkage to 'TestClassExtends' so I now have
PHP Code:




package{
    import flash.display.MovieClip;
    public class TestClass extends MovieClip{
        public function TestClass(){
        }
    }
}

package{
    import flash.display.MovieClip;
    public class TestClassExtends extends TestClass{
        public function TestClassExtends(){
            trace(test_mc.x)
        }
    }
}





This also works but if I now put the trace back in the superclass and leave the class as TestClassExtends

PHP Code:




package{
    import flash.display.MovieClip;
    public class TestClass extends MovieClip{
        public function TestClass(){
            trace(test_mc.x)
        }
    }
}





I get '1120: Access of undefined property test_mc'

How do I target this movieclip now from the superclass as I have 3 clips that are very similar in nature but just need slight variations in each so I want the basic methods in a main class as such
Any help would be appreciated


Cheers
Andy

Scaling Inheritance
Children inherit the scaling properties of their parents. If I don't want all the children to scale, what do I do?

(In this instance it's a caption box I want to be the same dimensions on all images. My Parent container contains an image and the caption box.)

I thought it'd be really simple. Something like

PHP Code:



ParentContainer.scaleY = 0.5;
spriteBackground.scaleY = 1 + (1 - ParentContainer.scaleY);
txtChild.scaleY = 1 + (1 - ParentContainer.scaleY);




Or should I just give up and stop nesting my captions in the image container?

Inheritance Issues
Working on a game for those who aren't familiar with me and my posts... I'm in the middle of restructuring all my code and I need a little help.

I have a class named Zombies that is extended by all the different types of Zombies... (RegularZombie, SuperZombie, etc.)
All instances of a zombie are stored in zombieArray in my document class... So when a class needs to access the zombies they just call the getZombieArray() from the root...

My Player class checks whether it's hitting a zombie using a simple for loop, and if it is the player takes damage, adds a bloodsplatter, and removes the zombie.

To take damage I call a line that looks like this
life -= z.getDamage();
Where life is a int value private to the Player class, z is the zombie it's hitting, and getDamage() is a method that returns how much damage the zombie does.

The problem I'm having is that getDamage() only returns what damage equals in the Zombies class... I need it to return what the type of the zombie the players hit's damage... Can I do this aside from overriding the getDamage() function in each of Zombies sub-classes?

Inheritance Problem
Hi Folks,

I have a great problem in my aplication. It have more than 250 classes, is a game framework, some times some classes presents inheritance problems, like losing the superclass.

Anybody already saw that and can help me?

Inheritance Problems...
I have this code:


Code:
class Main {
static function main() {
var test:SubClass = new SubClass();
trace(test.myVar);
test.increaseMyVar();
trace(test.myVar);
}
}

class SubClass extends SuperClass {
function SubClass() {
this.myVar = 10;
}
}

class SuperClass {
public var myVar:Number;
function SuperClass() {}
public function increaseMyVar() {
this.myVar = 100;
}
}
In different files as it should be. It compiles and runs, gives output to 10,10... I want it to be 10,100 of course... What's wrong?

AS2 Inheritance Problem
Hi,

I have created a new class which extends the XMLNode built in class. I want this new class to include all the functionality of the XMLNode (that's why I have extended the XMLNode class) and added some functionality. My new class which I am building is named XMLNodePlus.

I have added a getNodes method which will use the XPathAPI to search through some nodes in the XMLNode and return an array.

Is there a way where I can convert an XMLNode object to an XMLNodePlus object? That is, I want by some way to convert a parent class (XMLNode) to one of its inherited classes (XMLNodePlus). I would like to copy all the parent's class properties / methods defined by the XMLNode to an XMLNodePlus object which I have created to add some functionality.

I would really appreciate any help / workarounds . Thanks!

Inheritance Confusion
The more I work with AS3.0, the more I'm liking it. That being said, it still frustrates the bejesus out of me now and then.

I have a problem that I'll illustrate using a simplified version.

I have 2 movieclips in my Library that have classes associated with them via Symbol Properties. These classes (called "Sub1" and "Sub2" ) both extend a class called "Base" (and "Base" extends Sprite).

Both of these movieclips have a textfield inside, with an instance name of "txt". The initial setup of these textfields would be the same in both clips (ie. setting up the textformat), so I'd like to do that through my "Base" class.

In AS2.0 I would have no problem referencing that textfield from my "Base" class, but in AS3.0 if i use "txt" I get the ol' "1120: Access of undefined property txt." error. And if I declare "txt" as a variable in my "Base" class it comes up as null (I'm guessing because the Sub class hasn't been constructed yet).

Base definition:

ActionScript Code:
package
{
    import flash.display.*;
   
    public class Base extends Sprite
    {
       
        public function Base():void
        {
            trace( "new Base();" );
        }
       
        protected function init():void
        {
            trace( "Base.init();" );
           
            // throws an error
            trace( txt );
        }
    }
}

Sub1 definition:

ActionScript Code:
package
{
    import flash.text.*;
   
    public class Sub1 extends Base
    {
        public function Sub1():void
        {
            trace( "new Sub1();" );
            trace( txt );
           
            init();
        }
    }
}

In this simple example a reasonable solution would be to create the textfield at run-time in the Base class. However my movieclips in the real file are more complicated (lots of textfields and movieclips etc.) so it makes more sense to lay them out at authoring-time.

(i've attached a working example of my problemo)

Do I have any options besides dynamically creating everything at runtime in my base class?

thanks!
k.

Basic Inheritance
Hi

I'm just starting to look at AS3 and have come across a stumbling block.
Can anyone explain to me why I can't target a movieclip when I extend a class. For example I have a clip called 'test_mc' in a movieclip with a class of TestClass.
This works:

PHP Code:



package{
    import flash.display.MovieClip;
    public class TestClass extends MovieClip{
        public function TestClass(){
            trace(test_mc.x)
        }
    }





If I then extend this class and set the linkage to 'TestClassExtends' so I now have
PHP Code:



package{
    import flash.display.MovieClip;
    public class TestClass extends MovieClip{
        public function TestClass(){
        }
    }
}

package{
    import flash.display.MovieClip;
    public class TestClassExtends extends TestClass{
        public function TestClassExtends(){
            trace(test_mc.x)
        }
    }





This also works but if I now put the trace back in the superclass and leave the class as TestClassExtends

PHP Code:



package{
    import flash.display.MovieClip;
    public class TestClass extends MovieClip{
        public function TestClass(){
            trace(test_mc.x)
        }
    }





I get '1120: Access of undefined property test_mc'

How do I target this movieclip now from the superclass as I have 3 clips that are very similar in nature but just need slight variations in each so I want the basic methods in a main class as such
Any help would be appreciated


Cheers
Andy

Inheritance Question
Hello everybody.

I want to create a class A that extends the base class movie clip.
Then I want to create a class B that extends the class A.

Is this possible?
Do I write the code for the classes in the same .as file?
Do I write them in the same package?

Also in the main timeline I am planning to create an array of type A. Then I am going to create objects of type B and register them in the array.

Is this possible?
When addressing an object in the array as an A object, will the reference address the object as a B object?(funny sentence)

Thank you1

Inheritance Problem
Hello

I am running into a problem while trying to use inheritance and linking my custom classes to movie clips in my library. I have defined a custom class called "OptionTile" that extends the flash.display.MovieClip class. This class is meant to represent a basic option that a user can select in my movie. All the class does is add event listeners for the mouse over and mouse out event and displays a border around the option to indicate it is highlighted.

I then have some more advanced option tiles that change when the user clicks on them, however they also need the highlighting functionality that is defined in "OptionTile". So I thought this could be achieved by creating specific classes for each of the more advanced tiles and have these classes extend "OptionTile".

When it comes to the linkage dialogue box for my basic options, I have set the base class to "OptionTile" and just let flash generate the class definition. I can drag these tiles onto the stage and they function as expected. However when it comes to the more advanced tiles, if I set the class name to the class that I have created (the one that extends "OptionTile") and leave the base class as flash.display.MovieClip, nothing works when I drag the movie clip onto the stage. If I then set the name of the base class to the name of the class that I have created (the one that extends "OptionTile") and let flash generate a class definition for me, I get the same result when dragging the movie clip onto the stage (i.e. nothing works).

I also see the following errors in the output window:

Level.as, Line 1 - 1152: A conflict exists with inherited definition OptionTile.selection_mc in namespace public
OptionTile.as, Line 1 - 5000: The class 'OptionTile' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.

Level.as is one of my custom classes that extends "OptionTile". "selection_mc" is a movie clip that is on my tiles, this is just a white border that is set to visible when the mouse is over the tile and invisible when the mouse has moved out (I have used this to create the highlighting mentioned above). Both class definitions are in the same folder as the fla file.

I am quite new to ActionScript and ive ran out of places to look for answers! Ive tried searching for the errors on google, and the only references I can find seem to point to missing import statements in the classes. I have checked and double checked all my import statements and I am importing everthing that is used in the code.

Thanks in advance for any help!

Questions About Inheritance
I am working on a project in which I have a number of cables that are connected/disconnected. Because the code for toggling the states is used so much, I created a simple class to perform the task of unplugging/reconnecting the cables. In this class, I have a function called cableClick that simply toggles the state of the cable between the 2 states.
Now, however, I have some cables which the user needs to perform voltage tests on. In those cases, the cables has a third frame which we name "face". When in this face frame, the user can place a multimeter probe on any of the pins of the cable.
So, in order to code this, I figured I would create a subclass of cableClass (I called it voltageCbl). In this class, I added a new function called placeProbe which will place the multimeter probe over the correct pin. I also created another function called resynchProbes which will simply place the probes back in the appropriate places if the user leaves the scene before removing the probes and returns.
The question I have is... How do I call the placeProbe function? I don't think I'd want to create a new cableClick function if it is going to have nearly the same code as that in the cableClass. But then again, the cableClass doesn't know anything about the placeProbe function.









Attach Code

class classes.cableClass {
/*---------------------------------------------------------------------------------------
This class will only handle the functionality of cables as they are unplugged, show
the face view then replug them in. If the cable doesn't have a "face" view,
the class will automatically plug the cable in.
----------------------------------------------------------------------------------------*/
var cable, cblName, hasFace;
function cableClass(cbl, hasFaceView, idScrew) {
//Set up cable variables.
}
function cableClick() {
//Toggle state of this cable between "in" and "out" frames
}
function cableResynch() {
//Reset the cable back to its last known state - saved in external stateManager object
}
}


class classes.voltageCbl extends cableClass {
var testType;
var probePins;
var hasFace, cblName, cable, screwID;
var redProbe_mc, blackProbe_mc;
function voltageCbl(cbl, hasFaceView, idScrew) {
//Set up variables for voltage-tested cable
}
function placeProbe() {
//Place the Multimeter probe on the pin that was clicked.
}
function resynchProbes() {
//Replace the probes in their last known positions.
}
function cableResynch() {
super.cableResynch();
this.resynchProbes();
}
}

Inheritance Problem
Hi.

According to "ActionScript 3.0 Language and Components Reference" you "cannot use the override attribute on any of the following: Variables, Constants, Static methods, Methods that are not inherited, Methods that implement an interface method, Inherited methods that are marked as final in the superclass".

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/statements.html#override

So how can I have a boolean property in a subclass as true instead of false as in its superclass. Something like:








Attach Code

package {
public MyClass {

public var b:Boolean = false;

public function MyClass(){}

}
}

package {
public SubClass extends MyClass {

public var b:Boolean = true;

public function SubClass (){
super();
}
}
}


Thanks in advance,
T.

























Edited: 01/04/2008 at 04:50:35 PM by Plura

Inheritance Problem
Can you take a look at this code?
Although noFoot has no feet he still has 20 fingers. What´s wrong here? Does he have 10 extra fingers coming out of his head?



ActionScript Code:
function Extremities() {    this.hands = 2;    this.feet = 2;}Fingers.prototype = new Extremities();function Fingers() {    this.Fingers = this.hands * 5 + this.feet * 5;}twoFeet = new Fingers();noFoot = new Fingers();noFoot.feet=0trace("twoFeet has " + twoFeet.Fingers + " fingers");trace("noFoot has " + noFoot.feet + " feet");trace("noFoot has " + noFoot.Fingers + " fingers");

Stopping Inheritance
I have a bulletsystem where when u fire one it is attached to the movieclip that fired it, and I was wondering is there a way to make it so the bullets don't inherit their _parents x and y values and move as if they wer outside it but were still attached?....(that was one sentence)

Understanding Inheritance
Ok i'm trying to understand something here. I started off a project with a mp3 player I wanted to have one class for the sound controls and another for the drag sound position bar. So I had a bunch of properties and methods that I set up in the sound position bar class that I wanted to inherit from. So I thought after reading a bit on Inheritance its a piece of cake but yes I was mistaken or probably i'm more like stupid.

So I simplified the task a little to try and understand it all. I made an A and B class, B extends A. Here is the code and the output from it.


ActionScript Code:
//class Aclass com.A {    private var p:Number;    private var holder_mc:MovieClip;    function A(clip:MovieClip) {        holder_mc = clip;        trace("Class A Constructor working and desplaying the movieclip: "+holder_mc);    }    public function updateP(num:Number):Void {        p = num;        trace("P = "+p);    }}



ActionScript Code:
// class Bimport com.A;class com.B extends A {    function B() {        trace("Class B Constructor working");        updateP(100);        trace("trying to Inherit the path of the movieclip holder_mc from class A : "+holder_mc);    }}


In my FLA file I tried this

ActionScript Code:
import com.*createEmptyMovieClip("textClip", 1);var instanceA:A = new A(textClip);var instanceB:B = new B();


Here was my output:

Quote:




A Class Constructor working and desplaying the movieclip: _level0.textClip
A Class Constructor working and desplaying the movieclip: undefined
B Class Constructor working
P = 100
trying to inherite the path of the movieclip holder_mc from class A :undefined




Ok so first off I noticed that when I made an instance from class B it also called class A Constructor again? Is this meant to happen?
If it is meant to happen then what I’m trying to do will fail.
As you can see from the output that the calling of the A Constructor a second time has set my holder_mc property to undefined.
Meaning that when I try to access this property from the B class it will be undefined instead of been able to inherit this property from A.

This is so frustrating I have read so much on this and now it’s turning my head around in circles. Can someone please set me straight and fill me in on how I could achieve what I’m trying to do.

I’m really determined to inherit this new way of action script but it’s inherently a pain in the *** for me anyway. Please help

Inheritance Question
Hi! A simple (I think) question. Well, 2 classes in src/ihn:


Code:

//A.as

package src.inh{

public class A{

import flash.display.DisplayObjectContainer;
import flash.display.Sprite;


public var box:DisplayObjectContainer;

public function A(box:DisplayObjectContainer){
this.box = box;
}

public function traceA(){
trace('A method');
}

}//fine classe
}//fine package

Code:

//B.as

package src.inh{

public class B extends A{


public function B(){

}


}//fine classe
}//fine package
And in the flash timeline:


Code:
var a = new A(this);

var b = new B(this);

b.traceA();
This code gives me this error:

[color="Red"]1203: No default constructor found in base class src.inh:A.

(see next post: )

Inheritance Question
SCENARIO:

MovieClip in the library named "myMovie" which has class linkage of "ChildClass" and has a button on the first frame called "myButton"

ChildClass extends ParentClass

the ParentClass constructor looks like:

Code:
public function ParentClass():void {
myButton.alpha = 0.0;
}
and the ChildClass constructor looks like:

Code:
public function ChildClass():void {
super();
myButton.x = myButton.y = 0;
}
PROBLEM:
myButton is an "undefined property" to the ParentClass.

It looks like you aren't allowed to set class linkage and baseclass linkage simultaneously.
Any theories on how I should fix this problem?

Inheritance Problem
Can you take a look at this code?
Although noFoot has no feet he still has 20 fingers. What´s wrong here? Does he have 10 extra fingers coming out of his head?



ActionScript Code:
function Extremities() {    this.hands = 2;    this.feet = 2;}Fingers.prototype = new Extremities();function Fingers() {    this.Fingers = this.hands * 5 + this.feet * 5;}twoFeet = new Fingers();noFoot = new Fingers();noFoot.feet=0trace("twoFeet has " + twoFeet.Fingers + " fingers");trace("noFoot has " + noFoot.feet + " feet");trace("noFoot has " + noFoot.Fingers + " fingers");

Stopping Inheritance
I have a bulletsystem where when u fire one it is attached to the movieclip that fired it, and I was wondering is there a way to make it so the bullets don't inherit their _parents x and y values and move as if they wer outside it but were still attached?....(that was one sentence)

Class Inheritance
Hi

ive got a class, Particle (bit101's
particle class to be exact) that extends the movieclip class. So the way I invoke it by first setting its AS2.0 class in a movieclips properties to the class path. Then I just attach that movie clip:


attachMovie("particle", "particle1", 1);

now, i want to make another class, ParticleGroup, that uses the particle class and im not sure about how to do this. i would think i could do:

myParticle = new Particle();

which works, but then i dont have a physical movie clip associated w/ that particle like i do when i invoke it via attachMovie().

so instead, in ParticleGroup I tried to attach a movie clip that has the Particle class associated with it. But in order to not get compiler errors, i have to have ParticleGroup extend MovieClip.

class ParticleGroup extends MovieClip

I think this has the effect of overridding the association of MovieClip with Particle and I just get a basic MovieClip.

So what do I do? How do I have ParticleGroup contain Particles which are also MovieClips? Am I making any sense?

Billy

What Is The Real Low Down On Inheritance?
Hello all!
Having a difficult time sorting out all of the nuances surrounding class inheritance and movie clips. Take for example the following code:

// ------------------------------------------------------
// Bug Class
// ------------------------------------------------------
function Bug ()
{
this.init ();
}

Bug.prototype = new MovieClip ();

MovieClip.prototype.init = function ()
{
this.startPos = this._x;
trace ("start init: " + this._x);
};

Object.registerClass ("mc_bug", Bug);

// ------------------------------------------------------
// Scripts
// ------------------------------------------------------
counter = 0;

this.onMouseDown = function ()
{
addBug (this._xmouse, this._ymouse);
};

function addBug (x, y)
{
var newBug = "bug" + this.counter++;
this.attachMovie ("mc_bug", newBug, counter);
this[newBug]._x = x;
this[newBug]._y = y;
}

My expectation from this is that the trace statement in the init function would return the current _x position of the movie clip, which is also the _x position of the mouse when it was clicked. However, the output value is 0?!

Is there an issue with classes inheriting movie clip properties and the way that the properties are assigned. I just can't seem to capture any of the right _x or _y values when using this method.

Most articles I have read (or tried to read), approach inheritance in different ways and I am not sure which methods should be followed as best practice. Any thoughts from the forum gurus?

TIA

Variable Inheritance
I'm trying to put together a couple of MoviceClip prototypes - but I;m having problems.

Code:
MovieClip.prototype.colObject = function(hex) {
var col = new Color(this)
col.setRGB(hex)

var cRGB = col.getRGB();
var cHEX = cRGB.toString(16);

var newRGB = cRGB;
var newHEX = cHEX
}
MovieClip.prototype.fadeCol = function () {
trace("newHEX:"+this.newHEX);
}
my question is this then. How can I get the fadeCol function to inherit the local var's of the colObject. I realise I could delete the var, but I'm going to apply these function to around 500 MovieClips so I dont want permenant varialbes living inside each instance.

Inheritance Question
when inheriting a class do you also have access to the variables?
Wether public or private?
do I need to do this if myVar is in the super class?
trace(super.myVar);
or
trace(myVar)
Thanks in Advance!

The .prototype Inheritance Method
Hi everyone,
I have been using flash for years and have never even heard of the prototype method! I need to learn about this quickly! any online documents / tutorials? The manual (as always really sucks at explaining it!)

TIA

Steve

Removing Inheritance From LoadMovie
I am dynamically loading external MC's into my main program. I know that the loaded MC's inherit the settings (such as size) of the instance they are loaded into.

Is there a way for them not to inherit the properties?

I want to have the MC's use the properties that they have. Thanks.

Mark

Inheritance And MovieClip Objects
hi guys - i need a little help (in flash mx)

i am programming a game in flash mx using OOP but i have an inheritance question. I want to set an overall superclass that has all of the generic move and shoot methods and properties attached to it and then have 2 or 3 subclasses of that class which represent the different units with their own properties, movie clips (with the various animated states) etc.

i have tried this:


Code:
//superclass
mySuperClass.prototype = new movieClip;
mySuperClass = function (prop1, prop2) {
this.prop1 = "prop1";
this.prop2 = "prop2";
};

mySuperClass.prototype.moveMethod = function () {
//move method
};

mySuperClass.prototype.shootMethod = function () {
//shoot method
};

mySuperClass.prototype.onEnterFrame = function () {
//move/shoot
};
//etc

//subclass
mySubClass.prototype = new SuperClass ();
mySubClass = function () {
super (prop1value, prop2value);
prop3 = "prop3";
prop4 = "prop4";
};

//register class to subClass
object.registerClass ("movieClipName", subClass);

_root.attachMovie ("movieClipName", "instanceName", level);
Is this something i should be able to do or will i have to write a single object for each unit and duplicate all of the methods and shared properties?

hope you can help
;oB

Parameter Inheritance For Components
You create a component class A.
When you create a parameter with the Component Definition menu, this parameter seems associated with the clip and not with the class A.
So when a new component class B inherit from A, the parameter disappear from the inspector, and from the class itself.
To keep the parameter in the class, I have to create the corresponding prototype. But the inspector is still empty.
How can I inherit inspector parameters ?
My problem concern _targetInstanceName special parameter. I would like to keep the special property when I inherit from A class...
If anyone has an idea ?
Thanks for your help !

Movie Clip Inheritance?
hello out there!

anybody knows if it is possible to accomplish
the following task in actionscript?

[1] create a movieClip [name: circle
[2] create a couple of instances with actionscript on the stage
[3] change the tint of MC circle with actionscript
[4] all instances should inherit the new tint of parent MC circle

...do i need to create a new component?
...any ideas/help appreciated

regards,

deeno

Copyright © 2005-08 www.BigResource.com, All rights reserved