ActionScript 3.0 :: Calling Subclass Method Through Variable Typed To Superclass

Nov 26, 2008

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."

View 2 Replies


Similar Posts:


ActionScript 3.0 :: Overcasted Superclass Method Not Triggering Subclass Method?

Feb 1, 2011

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?

View 14 Replies

Actionscript 3 :: Call A Superclass Method From A Subclass?

Aug 15, 2010

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.

Here is the MAIN class (the superclass)

package
{
import flash.display.*;
import flash.events.*;

[Code].....

The code doesn't compile, I get "Call to a possibly undefined method DRAWTEXT through a reference with a static type class".

I realize there are otherways to display text on the screen. I just need to learn how to call superclass methods.

View 4 Replies

Actionscript 3 :: Change Subclass' Variable From Superclass?

Jan 3, 2011

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.

View 1 Replies

ActionScript 3.0 :: Calling Method From Superclass But Returned Error #1009

Oct 2, 2009

TypeError: Error #1009: Cannot access a property or method of a null object reference. the main idea is calling a method from subclass that inherit to a superclass.. here is the code

[CODE]...

View 3 Replies

ActionScript 2.0 :: Set Superclass Variables From Within A Subclass?

May 8, 2007

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?

View 4 Replies

ActionScript 3.0 :: Superclass / Subclass Movieclip Linkage

Oct 6, 2010

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)?

View 3 Replies

ActionScript 3.0 :: Superclass Logging Its Subclass Methods?

Feb 25, 2011

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") ???

View 1 Replies

ActionScript 3.0 :: Accessing Vars In SuperClass From SubClass?

Jun 12, 2005

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

[code].....

View 12 Replies

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

[Code]...

View 14 Replies

ActionScript 3.0 :: What Passes To A Subclass Extending From A Main Or Superclass

May 3, 2010

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?

View 2 Replies

ActionScript 3.0 :: Superclass Default Values Being Chosen Over Subclass Changes?

Sep 3, 2011

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.

View 3 Replies

ActionScript 3.0 :: Vector Of A Superclass Hold A Reference To A Vector Of A Subclass?

Sep 13, 2011

I'm getting

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?

View 7 Replies

Php :: Dynamically Typed Languages And Remote Method Invocation

May 31, 2011

Some may know that PHP methods can be remotely invoked from Flash.Sometimes the input parameter of a remote PHP method is an array of integers.Because PHP is dynamically typed an attacker can pass an array of anything.The array of integers has to be used in a SQL query.[code]

View 2 Replies

ActionScript 3.0 :: Calling Function From Subclass To Home / Doc

Jan 12, 2010

I seem to be having some difficulty calling a function from my subclass to home/doc class. I am trying to click the button called "GalleryButton.swf" (located in in Home page.as) to add a function called "addGal". (Also located in in Home page.as) to call a function from my main/doc class to work, called "gallery". Which indeed removes my home page from the stage and adds my gallery page to the stage.

I receive this error:
ReferenceError: Error #1069: Property gallery not found on flash.display.Stage and there is no default value.
at HomeClip/addGal()

EXAMPLE CODE - NOT FULL
I have import code such as:
import flash.net.URLRequest;
import flash.display.LoaderInfo;
etc etc. Because the pages to transition using buttons from the navigation class, its just that a button from homeClip.as, won't call the function "gallery" on the main class needed to add the gallery page to the stage.

Main Class - (holds the functions to add pages)
Code:
package {
public function StartHome() {
trace("addingHome");
addChild(_NavigationBar); //ADDS NAVIGATION CLASS//
_NavigationBar.name="NavBar";
} public function home() {
[Code] .....

View 9 Replies

Actionscript 3 :: Access A Superclass's Superclass In Flex?

Jan 17, 2011

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.

View 2 Replies

ActionScript 3.0 :: Calling Objects From Main Class In Subclass?

Oct 18, 2010

so i'm working mostly in a main class file. up until now subclasses (or the class for objects that i'm using in my game) have really only contained methods that controlled property values, and properties. however, i'm now interested in making an enemy in my game, but doing almost all the code for the enemy in the class file. i need to figure out how to communicate and check the object instance of the class against an object instance being controlled by the main class.

View 13 Replies

Flash :: Passing Strongly Typed Object To Method Expecting An Interface

Jul 26, 2011

I'm running into difficulty passing a strongly typed object, AttractView, to another method, addView() which expects an IWizardView interface that AttractView does implement. When I pass it as-is (as shown below), I get the compile error CaptureApplication.as, Line 120 1067: Implicit coercion of a value of type AttractView to an unrelated type IWizardView. Casting to either IWizardView or BaseView before passing yields a similar error at run time.

[Code]...

View 2 Replies

Actionscript 3 :: Change A Sublcass Variable From The Superclass?

Aug 18, 2010

This is basically the opposite of what I was trying to do earlier. I just need to know how to change a subclass variable from it's superclass. So if I were to make an object in a class how would I dynamically change a variable in that object from the original class that I made it in?

Suppose this is the main function of my main class:

public function MAIN()
{
new OBJECT_square().CREATE(this,100,100);
OBJECT_square.X = 40;
}

Changing the X value in this way is not working. I realize I can set/change the X value when I make a new subclass but I need to be able to change it as I go. I also realize I can change it from within the subclass but this isn't what I want.

View 1 Replies

ActionScript 3.0 :: Load External Swf And Set As Typed Variable?

Jan 28, 2010

So I have ClassA and ClassB. Each of these is the document class of two different FLAs. In ClassA I want to load a SWF and set it to a variable of type ClassB. The problem is that ClassB uses a ComboBox, so when I try to type the varialbe, then ClassA complains that it can't fine the definition for ComboBox. If I add the ComboBox component to the library of ClassA it works just fine. But that kind of defeats the puprose of me creating the seperate SWFs in the first place... smaller file sizes. So here is basic code of what I'm trying to do.

Code:
package
{
import ClassB;
public class ClassA extends Sprite

[Code].....

If I don't try to type the variable "swf" to ClassB then it works absolutely fine. But I want to have it typed so that I can then use intellisense/code completion in my IDE and not have to worry about the compiler telling em that functions don't exist on ClassB when I try to use them and such.

how to accomplish this? I have found that I can have ClassB implement an Interface and then set the swf to type IClassB... but I really don't want to have to do that because that means for all swfs I want to load I will have to create another Interface and prototype out all the functions. That just seems extremely tedious as this project will get very big.

View 2 Replies

ActionScript 3.0 :: TypeError: Error #1009 When Accessing A Method Or Property From A Subclass?

Jul 10, 2009

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.

View 1 Replies

Professional :: Can't Change Inspectable Variable Typed As Object

Jun 21, 2010

im currently working on a flash component (first time). I have an instance of my component dragged onto the stage. Played around with changing the different properties i made inspectable -  so here it comes: The property (typed object) i would like to change can not be edited in  the IDE. I have no plus icon to add a new name-value pair to the list

[Code]....
 
and a screenshot of my empty panel where i would like to add some  data:

View 2 Replies

AS3 :: Casting A Subclass Into A Parent Variable?

Jan 7, 2010

I am calling on different types classes from within a loop. The objects can be of different types so therefore I am using the getDefinitionByName method. here is a piece of my code:

for(var y = 0; y < mapH; y++)
{
brickHolder[y] = new Array();

[Code]....

But I got an error when I tried to call on methods. The interface is blank; doesn't have any methods in it. I am not sure if that makes a difference. But the parent class inherits it and the subclasses inherit the parent class. Can I instead use the parent class?

var brick:ParentBrick2 = ParentBrick2(new classRef());

In a nutshell, what can I do to loosely cast these objects so I am able to use any subclass methods that get called?

View 4 Replies

Set Variable In MainDoc And Access In A Subclass?

May 28, 2010

I am new to AS3 and am working on a project where I got stuck trying to figure out the best way to access a variable set in my MainDoc from a subclass. Nothing I've read has either made sense or seems like best practices. I understand a little about encapsulation to know that a subclass shouldn't be able to listen to a parent, but there has to be a way to do this with OOP in mind.[code]...

View 1 Replies

Java :: Flex - Calling A New Method From Mxml Produces "cannot Invoke Method" Error

May 24, 2011

[Code].....

getUser was already in UserService.java. I just created getUser2 and it's identical to getUser. When I try to call getUser2, i get the "Cannot invoke method" error. question: Do I need to specify getUser2 in some other file? like in some configuration file? if so, which one and how do I do it.

View 1 Replies

ActionScript 2.0 :: [OOP] Calling A Method In A Method?

Jul 24, 2006

Code:
class A{
function A(){
trace("construct");
}
private function moo(){

[code]....

yet this doesn't, I'd expect it to: construct, start mooing, moo!, moo!, moo!, ...yet the moo! moo! moo! doesn't appear, as if moo() never gets called it all.

View 1 Replies

Actionscript 3.0 :: Access A Variable From Subclass Which Is In A Parent Class?

Oct 31, 2010

I want to access a variable from subclass which is in a parent class.Something like this:

class a extends b
{
private var a;
public function a()

[code]....

View 6 Replies

AS3 :: Flash - Reference SubClass Of SubClass From Parent Without Instantiating?

May 1, 2011

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();

[code]....

View 3 Replies

ActionScript 3.0 :: Load A SWF And Calling A Method In It?

Nov 1, 2011

I have a preloader which loads a swf file, and once it's fully loaded it, it calls a function in it.

However, it doesn't seem to work. I get an error basically saying the function doesn't exist. [code]...

View 15 Replies

ActionScript 3.0 :: Calling Method From Another Class

Jan 10, 2011

I have two classes, in one (the Start class) I want to run a function I created in another (the Brown class). I commented in Start where I want to call the "addBrownListen" method. I tried doing it with the line:
Brown.addBrownListen();
But that didnt work.

Here are the two classes:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Brown extends Rebounders {
[Code] ......

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved