ActionScript 3.0 :: Inheritance / Interface - Override A Function That Return An Object Of Class A And Make It Return An Object Of Class B Which Extends A?
Aug 4, 2009
I'm having some troubles with the use of interface and inheritance in AS3. I've done lots of OOP in the past and what I'm trying to do seems obvious to me, but doesn't work in AS3. The question is : Is it possible to override a function that return an Object of class A, and make it return an Object of Class B which extends A ? It seems not to be possible, since I'm getting a signature error in Flash, when compiling. For example, the following set of class do not compile (the code in function definition doesn't matter):
I found myself loading a new XML file every day and so decided to create a small class that will load the xml file and return it.The class is loading the file but when i try to return it to a new xml object in the document class it doesnt load it.I think that it's something to with the return being in a nested function but i tried a few ways and non seems to work.
[DOCUMENT CLASS] loadXML:LoadXML = new LoadXML(); myXML:XML = new XML(loadXML.loadXMLFile("gallery.xml"));[code].....
I have a CSV reader class that parses a CSV file..... 1,11.15126526 2,11.28306635 3,10.78296071 4,10.79878325 The CSV reader class works and produces a Vector.<Point> ... However the container class (which includes an instance of the CSVFile class) needs to access the resultant Vector. Whenever I 'return' the Vector.<Point> to the container via a CSV method it is always empty...I don't know if its something to do with the size of the Vector<> or what?
I have a class CoverPoint extends Pointwith some extra function.except for that ther is no difference. I would like to use the functions of Point with a return value of Point, to calculate those CoverPoints.Can i turn the return value into CoverPoint (since all the vars are the same, there shouldn't be a problem with that, right?), so that it can be stored in my var cP:CoverPoint;
I'm trying to load a RSL library into a flash animation developed with Flash CS5 IDE, that extends a custom class and implements an interface. I have reduced the problem to the simplest setup and find that I can have my main class extend another class or implement an interface, but not do both at the same time if I want to load an RSL.I have a very simple class to extend:
import flash.display.Sprite; public class MySprite extends Sprite {[ code]...........
but if I want both I get the VerifyError: Error #1014 with MySprite not found and ReferenceError: Error #1065.
I am having trouble using inheritance, I made a class called newchars_2 that extends my class newchars and i get this error (newchars class extends movieclip): 1203: No default constructor found in baseclass newchars.
newchars_2.as: package { public class newchars_2 extends newchars { private var obj_no = 3; public function newchars_2() { //contructor class }}} And when I want to import this class do I import both the class's or just newchars_2 because it has all the functions inherited?
I'm trying to create a function that determines which of 4 similar classes to create, and returns the new object itself.
Basically, I have a base class (Panel) that has 3 additional variations in layout, each of which has a subclass: TextPanel, FeaturePanel, and LinkPanel. The two parameters for my function are the "kind" of window to create and its name ("linkString"), both of which are provided by external XML. I'm wondering if it's even possible to return the new Panel as an object...?
My code will probably explain this better than I can:
Code: // create the new Panel variable ("addPanel") with a call to newPanel: var addPanel = newPanel(linkList[i].attribute("kind"), linkString); Code: // newPanel function:
[Code].....
within the Panel constructor, the provided string (linkString / 'h') is set as the Panel's .name. I did not copy that function into the subclasses, since they inherit it - unless I'm mistaken.
I am trying to move text movies and textfields around a stage. This is a learning curve for me. I am confused by an example I have found on the internet.
Lets say I have the following inheritance hierarchy: Code: Select allpackage { public class ClassA { protected function foo():void { // do something }}} package { public class ClassB extends ClassA { [Code] .....
Now this is all well and good, as the call to ClassC.foo() will propogate through the inheritance chain; C > B > A. But what if I want ClassC.foo() to call foo() that is in ClassA and bypass the method call in ClassB? I have tried the following:
* Cast the method to the super-class type I want to execute, but this does not work as intended. Code: Select all... override protected function foo():void { // do something related to Class C // call ClassA.foo ClassA(this).foo(); }
I'm trying to have a class that is an Object to hold details about the movieclip that it is attached to.
[Code]....
and two others of this nature. I didn't think you had to declare the 'key' of the object as a variable before setting it in the Object. So my guess is that it is angry about the class itself, somehow. (syntax or the like)
I'm making a custom class and all my get functions are working fine except the one that returns an array. Here is the code for my class (abridged to the relevant parts):
ActionScript Code: /* VolcanicIsland class for Polypelago Script in progress
[Code].....
How do I get an array to return correctly? Doing trace(VI1.getData()[0]) doesn't work either.
googled it and hardly found any answer(seriously)need a quick solution for this:- How to create object from class that extends MovieClipSay i have a class name MC
The issue i'm having is that i want to have dispersed code-generated stars, and then they form a form (reindeer, santa, etc).
The idea is how i make the stars disperse and then return to their previous positions, knowing that the initial positions were randomly generated as well.
I have extended an mxml component with an actionscript class. I'm trying to access a component in the mxml file using the id (in order to add an event listener) but I cant seem to do it.
I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I followed the example from a previous question and I am loading an external swf using a loader and inside the loader event handler I am trying to cast the loader.content as my custom class PanelReferenceClip which extends MovieClip
When I publish I receive a this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Just to make sure and test that the swf location was correct and the swf was actually being loaded, I changed the type of the content to as MovieClip and it worked fine.
EDIT: I also wanted to add that these swfs are being stored locally and not being pulled across the internet, multiple networks or servers.
I am not sure if I did something quirky in my class so I am providing the source to my custom class PanelReferenceClip
It seems that dropTarget only returns the name of the object that is directly under the mouse. Does anyone know whether there is a simple way for it return the name of the object that is under the entire bounding box of the object being dragged?
public class Example { public function Example () { }[code]............
You can see that the two last classes extend the first one, and both have the 'variable' property. In case that I have an instance of Example and I am sure it is also an ExtendedExample OR AnotherExtendedExample instance, is there some way to access the 'variable' property? Something like
function functionThatReceivesAnExtendedExample (ex:Example):void { if(some condition that I may need) { ex.func()
i came across this problem and i have no clue why it's happening. basically, consider 2 nested movieclips on the stage, something like stage -> main -> filler. both movieclips have instance names (main and filler).
[Code].....
this throws an error 1119: Access of possibly undefined property filler through a reference with static type A. can anyone give me a hint on that, as it works with class A, but not B extending A? i understand it was meant to work?
The following is that long only because I gave examples of what I want to know, not because it is complex .I have three basic questions regarding AS 3.0 classes.
1. How can I make a class object interact with an object on stage?
For example, when I have a square (mc_Square) with class "square" attached to it and I want it to trace "Colliding!" and print the X and Y of the mc_Box on contact with an on-stage *hollow* box (mc_Box) that has no class attached to it.how to do it vice-versa would also be awesome .
2. How can I make a class object interact with the same class object? For example, when I have two squares (mc_Square) that both have the class "square" attached to it and when they collide, it prints the X and Y of both of them.
3. How can I make a class object interact with a different class object?
For example, when I have two squares mc_Square1 with class "square1 (that also has a variable Primary=true written in it)" and a mc_Square2 with class "square2"; When they collide, the one with Primary=true would be removed and it's X,Y position traced.
im creating multiple objects (the number is dynamic)they move randomly, but i want dont want them to be able to pass thru each other.i'm having dificulty on writing the hitTextObject code because I dont know how to refer the other objects.[code]
I am trying to write my first real class (it works when I just use trace statements). The main part of the function returns a value and since the constructor can not return a value I was not sure how to handle it, so I did this...