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


Similar Posts:


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 :: 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 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

ActionScript 3.0 :: Cant Get Shape To Refresh And Change / When Change Its Variable Using Text Field

Dec 3, 2010

Im really new to as3, and im just trying out some stuff, but i cant get a shape to refresh and change when i change its variable using a text field.If i change the text fields text before i test it, it works, but while its running it doesnt change it again.Btw, trying to change the stroke size.[code]i just want is so that when i change the strokeSize_txt text box, it will change the stroke for the shape.

View 2 Replies

ActionScript 3.0 :: Change String Variable To A MovieClip Variable?

Oct 10, 2008

I have been banging my head against a brick wall regarding the following problem which must be very simple to fix, just can't see the answer.I have a class assigned to a movieclip called canvas. The class is called drawClass. I have called the instance of canvas on the stage 'drawingCanvas'.When I trace "drawingCanvas" I get object drawClass] which is fine. Tracing drawingCanvas.name gets me the instance name 'drawingCanvas'.This is a String variable.Basically what I am trying to do is pass the MovieClip name to another class. In my example the class 'toolBar', which can then interact with the MovieClip.

The problem is passing 'drawingCanvas.name' results in a String, so I get an error saying :TypeError: Error #1034: Type Coercion failed: cannot convert "canvasArea" to flash.display.MovieClip.I can't for love or money find a way to convert a String variable to a MovieClip variable! I have the name of the MovieClip, I just need to tell the toolbar class. But I can't find a way of doing this as the instance on stage is an object of drawingClass, not a MovieClip (unless MovieClips with attached classes are not treated as standard MovieClips?).

View 9 Replies

ActionScript 2.0 :: Concatenate - Make The Variable Change With The Variable?

Jul 19, 2006

I'm trying to achieve something i thought would be extremely easy, but i can't get it to work!

[Code]...

View 1 Replies

ActionScript 2.0 :: Using A Variable To Change A Variable?

Jan 14, 2009

I'm creating a board game which has 3 variables, p1Move, p2Move and activePlayer.
p1Move and p2Move store the p1 and p2 location on a game board. activePlayer stored who's turn it is at the moment.

I am loading a value in from a text file which changes the value of move. This all works fine when i designate a player directly:

ActionScript Code:
p1Move = [insert variable name],

but i want to designate dynamically based on who's turn it is.

Something like this:

ActionScript Code:
_root["p"+activePlayer+"Move"] = Number(this.varAmount);

so that flash changes the value of p1Move (or p2Move depending on who's turn it is) to varAmount. varAmount is the variable being read from the textfile.

Hopefully that all makes sense. Basically i want flash to change the variable associated with the active player only.

View 9 Replies

How To Make SuperClass Available In Flex And Flash

Feb 4, 2011

I am working on a project that is utilizing Flash Professional and Flash Builder. The art team creates assets in Flash Pro and publishes the project as a SWC. I then copy the SWC into my Flash Builder project's lib directory and access the assets through that. The art team is creating a lot of the same type of thing; let's say they're making lots of lizard symbols/components. All of these lizards have similar animations (walk_left, walk_right, etc.) and because of this they all have constants defined in ActionScript (WALK_RIGHT_START, WALK_RIGHT_END, etc.) relating to the keyframes in their animations.

From the Flex side of things, whichever Lizard I load, I want to be able to tell it to walk left. So I created a superclass in Flash Professional and now all of the AS classes for the lizards in Flash Professional extend this class - Lizard.as This is all fine and good, but when I want to add more complexities to my lizards, I don't want to have to open up the Flash Pro project, edit the class, recompile the SWC, send it back to Flex, and then test it out. I want to be able to have my Lizard superclass available for editing in Flex - so I made another superclass in Flex: Lizard.mxml

In Flex, each lizard component (like Gecko.mxml) currently extends Lizard.mxml, and each contains an AS component defined in the SWC (Gecko.as in this case). This seems pretty convoluted: An mxml component extending an mxml superclass, containing an AS component which extends an AS superclass. What I'd like to do is define one superclass in the Flex project, have my Flash Pro defined components extend this class (which is the part I believe to impossible), and then have my Flex Components (Gecko.mxml) extend those.

View 1 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 :: Determine Whether Superclass Implements A Particular Interface?

Apr 8, 2010

Is there any non-hacky way to determine wether a class' superclass implements a particular interface?

For example, assume I've got:

class A extends EventDispatcher implements StuffHolder {
protected function get myStuff():Stuff { ... };
public function getStuff():Array {

[Code].....

How could I perform that super is StuffHolder test in a way that, well, works? In this case, it always returns true.

View 3 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 :: Determine A Class's Superclass At Runtime?

Jul 13, 2011

In Actionscript 3, if I'm given a Class object, is there any way to determine if that class extends from another given class? I don't want to instantiate the class to check it with the is keyword, though.

[Code]...

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 :: Convert Vector Type To Superclass?

May 20, 2011

I have a class which takes a Vector.<DisplayObject> in it's constructor. I had expected it to be ok to create instances of this class by passing Vectors of types that are subclasses to the DisplayObject class (in this case Sprite ans SimpleButton). But it doesn't work. And casting these Vectors as Vector.<DisplayObject> when declaring the instances doesn't work either. [code]...

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 :: Adding Functionality To A Superclass Function

Feb 26, 2009

just made my jump into OOP and I am quite excited to find out such marvelous things that I did not know. If someone has a quick answer or can point me in some direction please reply to this question: How can I, if at all possible, modify a function from a superclass but preserving all of it's functionality? I know about the "override public function" but that is not precisely what I want.

View 5 Replies

ActionScript 3.0 :: Cannot Create Dynamic Property On SuperClass

May 25, 2009

I'm not sure if this is a bug, or an expected behavior, but, if you try to call super["dynamicProperty"], given that superclass is dynamic, it will throw error telling you that the dynamic class <name of dynamic class> has no property "dynamicProperty". BTW, the extending class is dynamic too.

View 2 Replies

ActionScript 3.0 :: Access Inherited Property From Superclass

Feb 15, 2012

Sorry to bother you with this thread, because I'm sure it's pretty obvious, but I can't see through it.
With this following code, I can't access the visible property of the Sprite class...

[Code]....

View 5 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 :: Accessing Superclass Methods On An Externally-loaded SWF?

Jul 27, 2009

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.

[code]....

View 11 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

Change Value Variable In Other MC?

Jul 8, 2009

I have an flash movie with on the main timeline a movieclip "MC1". In this movieclip I have another movieclip "MC2". On the first frame of MC1 I have declared a variable x and I want to give this variable a new value when I click on MC2 but it doesn't work?!

Main timeline: 1 frame with MC1

MC1: 1 frame with MC2

Codes implemented on the timeline:

MC1:
x;

MC2:
onMouseDown = function() {
_root.x=1;
}

Example: [URL]

View 4 Replies

ActionScript 1/2 :: My Variable Won't Change

Jun 19, 2009

I am attempting to make a remoddled clone of the game at [url]...so far i have some blobs that slowly move down through a door, then when they're off the screen they jump back above the screen to come back down.my problem is that the door is user controlled using this code on a butten[code]...

View 1 Replies

Change An Integer Variable Per Second?

Jun 22, 2009

I'm working on a game were your health variable will add 1 hp automatically every second if the health variable is not equal to 100. How would you do that?

View 1 Replies

ActionScript 3.0 :: Change The Name Of Variable?

Dec 10, 2009

can I set variable from QueryString . if yes , then HOW ?

for-Example :

FLASH:
var myvar:String;

I want to change the name of variable (which is already declared in Flash ) from querystring

like myvar+new

is that possible , I change variable name again from QueryString?

View 1 Replies

ActionScript 2.0 :: Change The Value Of A Variable?

Mar 14, 2011

I have a variable set up on my actions frame. It is var bucket:Number=0 .I want bucket to equal one if one object hits another.

View 9 Replies







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