ActionScript 3.0 :: Return A Value From An Extended Sprite Class?
Jul 14, 2009I created a menu from a created .as extended Sprite class.
Except from this menu, I need it to return a String value of the item name the user selected.
I created a menu from a created .as extended Sprite class.
Except from this menu, I need it to return a String value of the item name the user selected.
i've only ever created external .as files that extended a class such as sprite. now i just want to create one that doesn't extend anything and call it from a frame script.
[Code]...
I have 1 class (that is extending a UIcomponent) that is representing a component. In that component I create different instances of another class that is also a UIComponent but this class doesn't show up in de first class. I see that it is running and that it has the correct hights but I got the feeling that it doesn't show up with this hights. If I trace I see the width and height is 200 X 200 but there is still nothing visible in my component.
View 1 RepliesI'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):
[Code].....
If I have three classes:
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()
package{
public class Character{
protected var _hp:uint = 50; //Character Health Points
protected var _power:uint = 5; //Damage dealt
[Code].....
I`m instancing a Character and a Player in the Main Timeline, all in frame 1.
When I use: ""player.attack(character)"" it works fine by itself.
So I added the if (defender._hp <= 0) this.win() which gives me the following error:
1061: Call to a possibly undefined method win through a reference with static type Character.
"defender" is a Character instance, "this" is a Player instance and "win()" is a Player method. I try to call the Player method inside a Character method using the Player instance adding the "." and his method name
Do I really need to define the win() function in the Character class? Is there a bypass to use a subclass method in a parent class method if it`s called from an instance of the subclass?
I created an flv video player using Flash Builder 4. This "BasicVideoPlayer" project is compiled into a SWC that will be eventually be used to create other video players that extend the functionality. One of the features is a view that appears when the video has finished playing that displays a "Play Again" button. This "Play Again" view has its own class, "BasicPlayAgain", that accepts a graphic asset that is exported from a .fla file that contains all of the graphic/UI assets.
In my new project, "EnhancedVideoPlayer", I'm using the BasicVideoPlayer SWC as a library to create a new video player that will add more functionality to the "Play Again" view; specifically it will add more buttons to that view.The EnhancedVideoPlayer uses a default class that extends the BasicVideoPlayer class. The BasicVideoPlayer class has a member called "playAgainScreen" whose type is BasicPlayAgain. The EnhancedVideoPlayer needs to override the playAgain member and recast it as EnhancedPlayAgain so it can control the new buttons properly.
Let's say Class A has the flash.events.Event imported. Now let's say Class B extends Class A. Why in the hell do i need to import flash.events.Event in Class B? It makes no sens at all to me.
View 3 RepliesThe use of library classes confuses me once again. I have the following situation:
[Code]....
I cannot put in any baseclass when using the class, so I'm forced to remove the baseclass. When using only the class I get a whole bunch of errors don't make any sense at all, and still appear even if I comment out all the code in the Page class. comop_padpagesFavorietenPage.as:7: 1152: A conflict exists with inherited definition com.op_pad.pages:Page.help in namespace public.
[Code]...
Is it possible to dispatch event from class that isnt extended class of MovieClip? I created my own class and put import flash.events.Event; import flash.events.*; but when i call dispatchEvent compiler throws error:"1180: Call to a possibly undefined method dispatchEvent."
View 3 RepliesI have created a class (extends the Event class) for use in one of my projects. If I trace the custom event object in the called function I get 'Event' as the type, but if I trace a TimerEvent, or MouseEvent, etc, I get TimerEvent or MouseEvent... Let me demonstrate:
var c:CustomObject = new CustomObject();
c.addEventListener(CustomEvent.ON_SEND_MESSAGE,fnc);
function fnc(e:CustomEvent) {
[Code].....
I created a class, extended the sprite class, and now in the constructor I am trying to set the Sprite's width and height properties which are inherited from the DisplayObject. However, after I set this.width and this.height, and print the values, I get 0 for both.
What the heck is going on? When I view the livedocs I see that DisplayObject has width and height listed as public properties. I have been able to instantiate a Sprite directly, and set the width and height after it's been instantiated, so I don't get it.
package {
import flash.display.*;
public class ScrollBar extends Sprite {[code].....
I want to load two picture and add every picture to every sprite object,such as picture a to sprite1 and picture b to spriteb,I know I can load a pictue by following code:
loadImage('a');loadImage('b');private function loadImage(imagePath:String):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded); loader.load(new URLRequest(imagePath));}private function
[code].....
I want to load two picture and add every picture to every sprite object,such as picture a to sprite1 and picture b to spriteb,I know I can load a pictue by following [code]...
View 2 RepliesOk, I have spent a little time searching and I can't seem to find an answer to my question, maybe I'm asking the wrong question. here's my situation:
I have a document class called Main.as, this class has variables that instantiate a CreateShape.as class that acts as a superclass. The CreateShape.as class has a protected function that is overridden by other classes (I have a CreateCircle, CreateSquare etc). Those CreateCircle etc classes, use extends to extend the CreateShape.as class, and thus have the ability to override the main method (called newShape()).
[Code]...
I have my main stage, and I have two objects (blocks), these two objects both extend from the "Block" class. The "Block" class is NOT extended from the Main Class.I would LIKE to call a function, in either the "Block" class or in it's subclasses, from the Main Stage Class. The functions will do slightly different things depending which object you are calling the function (Added different things, and different number of things to an array). What is the best way to implement this?
View 2 Repliesi have this class but instancing it nothing appear
class myclass extends MovieClip
{
var mc:MovieClip;
[code].....
Is there a way to hide properties or methods of an extended class?Ie, I want most of the extended properties and methods to be accessible but I want to hide others and use my own instead (not just overriding).
View 2 Repliescapturing an event from extended class. i am extending class B from class A. snippet form class A (ButtonControl):
[Code]...
I'm having some trouble with using a Document class in Flash CS3 that is an extension of another class. When I do this, I can no longer make references to MovieClips with instance names on the stage.Here's an example. I have a class called Minigame that extends MovieClip and then a class Shooter that extends Minigame. So the relationship looks like:MovieClip <-- Minigame <-- ShooterI want to use Shooter as my Document class in the Flash file Shooter.FLA. However, when I do this, I am unable to directly access any instance names of MovieClips on the stage of Shooter.FLA from Shooter.as. In other words, if I try to write the line:var mc:MovieClip = this.instanceName;in Shooter.as, I get the error:1120: Access of undefined property instanceName.
View 1 RepliesI'm new to AS3 and I'm having a problem with an extended class that uses a URLRequest. I have a basic class called 'imageLoader' that I use for loading in external images
[Code]...
If I have a class that extends another, e.g.,
package {
import flash.display.Sprite;
public class MySprite extends Sprite{
[Code]....
and extend that class, if more than one internal classes are defined:
package {
public class MainClass extends MySprite {
public function MainClass():void{}
[Code]....
ReferenceError: Error #1065: Variable MainClass is not defined.Note that this only happens (as far as I can tell) when the public class of the package extends another class, and multiple internal classes are defined. The internal classes don't even need to be instanced or referenced to generate the error (the bare-bones code above will error out). If only a single internal class is defined, it works fine (no error). Even if the internal class is instanced.
All my custom classes that extend MovieClip simply trace as "MovieClip" when using stage.getChildIndex(i); I'm trying to search the stage to see what objects have been placed and then add them to the correct array. E.g. if I place 5 "Enemies" on the screen, I want to then add them to an array by searching the stage for the "Enemies" class, without naming each one and adding it manually in the code.
Edit:
Code:
for(var i:int = 0; i < stage.numChildren-1; i++)
{
trace(getQualifiedClassName(stage.getChildAt(i)));
[Code]....
I have recently started out with flash oop concepts and was wondering how to do create an instance of an extended movie class without dragging and dropping the clip from the library ....I have figured out this method..
for(i = 0;i<100;i++)
{var mc:MovieClip = attachMovie("ball","dasd"+i,_root.getNextHighestDe pth());
mc._x = Math.random() * 600;
mc._y = Math.random() * 600;
}
but this way I cant pass arguments to the constructor function of the ball class..
I have some movieclips on my main timeline with a class to extend these movieclips
[code]...
But the I can't 'reach' the testing function. I get this error: "1061: Call to a possibly undefined method testing through a reference with static type flash.display:DisplayObjectContainer."
I've created a Button in Adobe Flash CS5, it's a Symbol, and its type has been set to Button.
The button has a dynamic textfield with the instance name label.
I've set the class of this Button to MenuButton, and I've set the class to Export for ActionScript.
This is the code of the MenuButton class:
Code:
package
{
import flash.display.SimpleButton;
import flash.text.TextField;
[Code]....
Whenever I put a string in MenuButton's constructor, label's text doesn't change.
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 BasicMap.as that takes an Array and populates itself with the MC objects passed to it by a String reference.it inherits from Sprite, and so it just places the objects on its self.then i have a class that inherits from that class, and gives a little more functionality to it, but in order for it to do that, it needs to place the objects not on itself, but instead inside a holder Sprite, so here is my problem:
code:
package Mushroom{
import flash.display.Sprite;
[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...
[Code]...
How would I return a value from this class?
package com.ryancanulla.utils
{
import mx.collections.ArrayCollection;
[code]......