ActionScript 3.0 :: Accessing Vars In SuperClass From SubClass
Feb 24, 2012
So, how would you create a class that can access a variable in the class where the subClass was created(superclass), I realise this might be unclear so in example
So, how would you create a class that can access a variable in the class where the subClass was created(superclass), I realise this might be unclear so in example
PHP Code: package {import flash.display.MovieClip;public class Main extends MovieClip {public va demoString:Strin = "TEST";public static var newClass:SubClass;public function
1: Is there a way to set superclass variables from within a subclass? I can't seem to accomplish it.
2: Also, why does it seem when I call a function, the superclass version is called instead of the sub? I construct the class using the sub, so whats the matter?
3: In one of the classes, I want to push a MovieClip it creates into an array, it works, but I get an undefined, then the value.
4: I have 3 levels of inheritance in my classes Specials -> Human -> Player, who do i call each one correctly from one another?
I have a Hero class that extends a Unit class that extends a SelectableObject class.[code]I have a movieclip in the library that links to the Hero. Inside the movieclip is another movieclip with the instance name "selector".In the Hero I can use selector.gotoAndStop (n) because the movieclip is linked to that class, but I can't do that for the SelectableObject because it's not linked to that.Is there a way to make selector.gotoAndStop (n) work for the SelectableObject? I can't even do var something:* = this.selector because the movieclip isn't linked to it.Or should I just remove the instance name for the selector in the movieclip so I can declare var selector:* = this.getChildAt (1) in the SelectableObject (the selector being the second child)?
What I would like to do is to call a method from a superclass in a subclass. Specifically I want to be able to add the subclass as a child of the superclass but without physically having to type addChild in the superclass (but I will have to type it in the subclass). For now I'm just trying to call a method in the superclass that draws some text from a subclass.
For some time now I have been making a very easy game for iPhone in flash using as3. Recently I came in contact with a small problem, which is why I am posting this!
The problem: I have a superclass from which everything derives. In the superclass I initiate and place an Object on stage.
1. var myObject:typeA = new typeA();
2. stage.addChild(myObject);
As you can see this object follows the class 'typeA' which, ocf, has its own actionscript file. Inside of this file I have declared a global variable of type string.
What I want to do is change the varbiable on the new object from the superclass. Therefor I tried as following:
1. myObject.myVariable = 'someSortOfString';
Unfortunatly it didn't work and so I wonder how to do this; change a subclass' variable from the superclass.
I have an abstract superclass which has around 300 subclasses. I would like to log when certain methods on this parent are called, and I'd like to know the name of the subclass thats making the call. Is there any way to do this without rewriting all my subclasses to explicitly pass their names upwards to the parent's logging method? E.g., let's say I have a superclass Foo with a method writeLog(str). Foo has a subclass called FooBar, which calls super.writeLog("hello"). Can writelog just inherently figure out that a FooBar called it, without the need to rewrite everything so that we have to call super.writeLog("hello", "FooBar") ???
What passes to a subclass extending from a main or superclass, be it document or extending from a general MovieClip class etc? Does it pass absolutely everything from the superclass? That is to say, instance functions, variables defined inside these functions etc? Or just constructor variables? What passes through and does 'static' affect the transference of these values?
I've run into an extremely odd problem. I'll give a code example to start. This is the superclass Building.
Code: public var allowsEnemyMovement:Boolean = true; public var information:String = ""; public var buildingName:String ="";
[Code]...
Now here's the odd part. Only SOME of the variables defined in the superclass do this. the variable information, buildingName and health all will take the default value from the super class. But the variable defenseValue will take its value from Factory's constructor. What am I doing wrong here? I would like to keep default values in the superclass so that I don't end up with null pointer errors later just in case.
It's early days in my AS3 learning, and I'm looking for a little clarification regarding a variable typed to a superclass (in this case var mySpinner:MovieClip) which contains a reference to an new instance of a subclass (in this case Spinner.) I am trying to get my head around why my code compiles and runs and I am able to call the method rotater() on mySpinner even though mySpinner is typed as MovieClip, and the MovieClip class does not contain the method rotater().
On page 163 of the official Adobe Programming ActionScript 3.0 documentation it says the following, which I believe is related to my situation, but I am still in need of clarification: "Because each class defines a data type, the use of inheritance creates a special relationship between a base class and a class that extends it. A subclass is guaranteed to possess all the properties of its base class, which means that an instance of a subclass can always be substituted for an instance of the base class."
ActionScript Code: 1067: Implicit coercion of a value of type __AS3__.vec:Vector.ie.aro.floorplanviewer.model.buildingVOs:ConfigurationVO>[code]....
which surprises me as ConfigurationVO inherits from NodeVO.Is the compiler really not able to figure out that a Vector of a superclass should be able to hold a reference to a Vector of a subclass?
I have a class called Animal that has a method foo() and I call it out within the Animal class.
Code: protected function foo():void { trace("Animal"); }
I also have a class called Cat that extends Animal and overrides the method foo()
Code: override protected function foo():void { trace("Cat"); }
However when calling the function foo() from the superclass it traces out Animal not Cat (using a Cat object).How can I make superclass call out methods in the subclass?
I'm trying to set up a large project that has a "shell" application that preloads and eventually displays a bunch of SWFs as a "slideshow". Each SWF could be authored by different people but will reference a base document class so they exhibit consistent behaviour. One of these behaviours is to be able to localise the slideshow into different languages. Since each SWF could have a different number of textfields that need to be localised embedded into their main timeline, the SWFs each must declare their stage instances in their document class. In order to implement the common functionality (such as a "localiseText()" method), I have decided to package all common functionality into a superclass (what I'm calling "Base Class" in this example) and using a subclass as each slide's document class.
This Example:This is a simple example I set up because in my actual project my compiler was throwing a coercion error when I tried to cast the Loader.content as my external class. The structure of this example is the following:
+ loader.fla : this is the main "shell" application. + SWFLoader.as : the Document Class for loader.fla + external_1.fla : this is the external SWF file that will get loaded and displayed
[code]....
I've set it up this way because a hypothetical external_2.fla might have different public variables to declare its stage instances so would need a separate implementation of ExternalBase (presumably External2.as).
The code (in reverse):
base/ExternalBase
[code]....
This just sets up the localiseText() method which is used in this example to change the contents of the text field. Since we don't know the name of the text field in the particular slide's timeline, we have to ask for it from the subclass' implementation of getLocalisableTextField(). We declare an abstract function here that needs to be overridden in the implementation.
I am building a app that pulls data from xml. The different nodes in the xml needs to build different objects. My thinking was that I must import the xml only once. Then build seperate classes for each object type. These classes will extends the xml class and apply whatever it needs to do with specific nodes data. Problem is that it seems like the subclass is created before the xml loaded. I can trace the xml data from the xml superclass but not from the subclass.
Main Class
Actionscript Code: package MyClasses{ import flash.display.Sprite; import MyClasses.Dateline; public class Main extends Spriteprivate var dateLine; public function Main() dateLine==new(Dateline);}}
I'm trying to override a subclass's method but I think I need access to the superclass one higher up in the hierarchy. So I'd like to do something like super.super.methodName();
FYI, the actual problem I'm trying to solve should be explained by my code below:
public class A extends UIComponent{ override protected function keyDownHandler(event:KeyboardEvent):void{ super.keyDownHandler(event);
[Code]....
If I use the class A's KeyDownHandler method, you will see that remove() is called regardless. However, the docs state that I need to call UIComponent.keyDownHandler whenever I subclass UIComponent. Of course this works for the first subclass, but not that subclass's subclasses.
I realise that I could put the functionality all into A with something like if(this is B){...} but that seems to me to be a hack.
In my flash document, I have a movieclip drawn on the flash stage (put there myself, not dynamically). I want to use this as a holder for an external .swf. I am using a sub-class to run the loading script. I pass the stage reference to it as the variable "theStage". It has no trouble loading things directly to the stage, but it can't find my movieclip for some reason. I have exported the movieclip for actionscript in the symbol properties panel and have given it an instance name.I've tried theStage.myMovieClip.addChild(mySwf); and suchlike, but always get this error message in output:ReferenceError: Error #1069: Property myMovieClip not found on flash.display.Stage and there is no default value.at MethodInfo-206()Some more information: It works from the main class without any trouble.
I'm using a preloader to load an external SWF then initiating it through its document class using this code:
Code: private function loaderCompleteListener(event : Event) : void { var loaderInfo : LoaderInfo = event.target as LoaderInfo ;
[Code]....
The problem i'm getting is that the Flash that is being loaded has a lot of classes exporting on the first frame, which now cannot be accessed, and therefore I get "The definition of base class cannot be found" errors.
How do I ger the items in the library that export to AS accessible by the parent loading SWF.
I've been working with/around and dodging a situation where I'm trying to access FLA library movieclip assets, but NOT from the document class. I capitalize this because this is my 4th forum posting. I know the answer to that one:
instanceName:ClassName = new ClassName();
The easiest solution for accessing library items from a SubClass looks to be this:
// at topimport TestLocalMC;// in constructorvar box:TestLocalMC = new TestLocalMC();addChild(box);
However, it doesn't show up. I tried a fake non-existent class. It gave me an error so I know it's referencing a Class in the library that I supplied. If I trace the object, it shows up. If I trace the X value, it says 0. So logically, it should be right in front of me..but it's not there! .Am I on the right track? Is this familiar at all to anybody? Is there something I'm missing?
if I could reference FLA library items with a bit of freedom from the document class. Having to go up the hierarchical class tree everytime to retrieve a movieclip is getting rather painful.
I am hoping someone can explain about subclasses accessing variables from the super class. I found that the subclass can only access variables which are set in the constructor of the super class. Is there any way around this?
I am writing a program in OOP and I have a custom subclass which I make a new instance of in the document class. When I do make a new instance of this custom class, I want this (the custom subclass is a movieclip) object to be positioned at the center of the stage. However, when I try
how to access library items in the main SWF directly from a SubClass by doing this:
package{ import SubClass; public class Main extends MovieClip{public var mySubClass:SubClass = new SubClass;this.addChild(mySubClass); }//class }//package
package{ import Box; public class SubClass extends MovieClip { public function SubClass():void{var train:Box = new Box;this.addChild(box);}//SubClass constructor function }//class }//package
But how do I access library items of a loaded SWF in the same fashion? Importing is different from loading and I'm not sure how or where to piece instances together at runtime.
I'm trying access a static variable located of a super class through an instance of one of it's subclasses and I'm receiving an access of undefined property error (example of which below). Creating another static variable in the subclass and assigning the value from the super class will allow me to dot operate to it.
error When your accessing a method or property from a subclass. Here's what I have done so far but no luck in my script.
1. I tried waiting for my attached movieclip to be added to my stage using the setTimeout method but no luck.
var timedProcess:Number = setTimeout(initRevealDropDown, 1000); private function initRevealDropDown():void { clearTimeout(timedProcess); var myInterface:Interface = new Interface(); myInterface.revealDropDown(); }
2. I also tried extending my subclass to interface where my instance method is defined for revealing my dropdown menu, no luck on that one.
I'm working in flex, but using as3. I have two components, and need to communicate between vars. I have my main app, and two components. I declare "newsDB" in the main app like this.
[Code]..
This gives me an error like so TypeError: Error #1009: Cannot access a property or method of a null object reference. I get that it is trying to touch the var before it is implemented. How should I go about this?
how can i call public functions or vars of a sprite class from another class (or frame script)? i keep getting 1061: Call to a possibly undefined method getSide through a reference with static type flash.display:Sprite.
//Framescript var a:Sprite = new customRect(); addChild(a);
I'm trying to access a variable from my main movie in a loaded movie. I can't get it to work however. The movie loads into the main movie but I can't access anything from that main movie. I see that there a few write ups out there about this, but I just can't get it. I attached a zip as well as the source below.
here is the main movie script
function mainTimeline() { trace ("Just friggin work already"); } var myNumber:Number = 5;
I have an xml content loaded in AS and to that content I made a movieClip to show that content.I'm duplicating that movieClip according to the quantity exposed in xml.My problem is that when I duplicate de movie clip, I don't find a way to contact the dynamic texts variables.Her's the dynamic texts vars:- client_number;- client;- ...Her's the code:
Code: var my_xml = new XML(); my_xml.ignoreWhite = true;
Can I access a static variable of a subClass' subClass? I don't want to instantiate it, just looking to get the variable because it has already been initialized by the subClass.example:
package { public class A extends MovieClip { private var classB:B = new B();
MovieClip(parent).tiles.["cell"+MovieClip(parent).current_cell].text=="Quiz" where : MovieClip(parent).tiles - Movie Clip in parent directory. ["cell"+MovieClip(parent).current_cell] - cell + variable which is a number Checking for condition than the Dynamic textfield area text is equalto "Quiz".
Gives an error : 1084: Syntax error: expecting identifier before leftbracket. 1084: Syntax error: expecting rightparen before leftbrace.