ActionScript 3.0 :: Make Subclass For Event And Using It?
Oct 16, 2010
I am having a problem with Event class, kind of. My goal is to pass some arguments on the function that get triggered when event is complete. This current code forwards an Event not a CustomEvent, if I am correct.[code]...
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();
With MXML components, I've seen a pattern used where you have an AS3 class, then the MXML subclasses it, to have a separation between view/code (anonymized from real code):
package com.john { public class MyComponent extends Canvas {
[code]...
At least I think the MXML component is subclassing the AS3 class?Anyway is it possible/advised to do this with my main MXML application file, so I can put manager instances and things in the AS3 MyApp class, which is subclassed by Main.MXML?
I'm moving on to my next massive programming project and I'm trying to decide whether I should code it in as 2.0 or 3.0. I came across the new click event model in 3.0. Right now it's looking like a pain in the butt to me. So now I have to make a function and add it as an event listener? what the hell? What's the benefit? I understand stuff like this makes AS a more complete language but it's kinda annoying.
When game starts, the car runs automatically. Then we click the SPACE button, movement of car stops. And the door of structure near car is available to CLICK.
But in coding I got this error code:
TypeError: Error #2007: Parameter listener must be non-null. at flash.events::EventDispatcher/addEventListener() at shfg_fla::MainTimeline/key_pressed()
This is some part of my game code...
case Keyboard.SPACE : removeEventListener(Event.ENTER_FRAME,car_movement); --street_mc.bluehome_mc.door_btn.addEventListener(MouseEvent.MOUSE_DOWN,door_ready)
I have a document class and a subclass. In the subclass I have a trace. I've done this dozens of times before.I've checked everything and I'm stumped. I can't for the life of me figure out why it's not running a trace.
I checked AS3 settings like usual. The FLA finds the document class but I can't get the subclass to show up.[code]...
I create a Sprite in a subclass, add it to the stage. Now I need to target it from another class, but I am going wrong somewhere. This is shorten code, so hope I did not delete some important parts. But you should be able to follow the basic structure.
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);}}
How do you subclass multiple classes. I have a class that subclasses MovieClip. I added a new feature. Now its yelling that my class needs to subclass SimpleButton. I know there both part of the display class. But how do you subclass that?
I'm running into the situation where I can't instance a SubClass in the above SuperClass because the SubClass is extending from the SuperClass.
I get stack overflow. Fair enough, right?
Well, I want to add this SubClass to the display, and the only way I know how to do that is through addChild(). To addChild() I need to instance the SubClass.
I can't put any visual display instance or events in this subclass because it's currently null and extends is keeping me from doing so. It's great cuz I can share all the goods, but now I'm stuck dancing inside functions because I can't use events on the main "timeline" of the null SubClass.
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?
I want to subclass "superClass" and override one of it's functions.
[Code].....
The problem is that the "superClass" is loaded from a swf. I do not have a reference to the class definition in my project. Is there a way to do something like below?
I have my main.swf which has class of Main.as which control everything.Then in main.swf I have 3 movieclips that acts as a button and they share a class of Button.as which controsl all the button functions btn1, btn2,bt3 are all place on stage and in Main.as I control their positions.When you click on a btn, it moves to a new location at the same time the other 2 btns will move as well.I can get the target btn that's been click to move just fine, but I can't get the other 2 btns to move and they all share the same class. I know this probably has to do with a targetting issue... I think. Is there a way I can make the connection in same Button.as class file? Or do I use like some global event dispatch?
I'm trying to access a button through my subClass, the button I'm trying to access is located on timeline and this is the error I'm getting once I run the code:1120: Access of undefined property btn_Test., maybe someone could look at the following code and indicate what cause the error
So I am trying to create a document class for my program, and I know all the code is correct because I already have the program working.I am currently trying to rebuild the program, and I simply copy and pasted all the working code into my new program.I have 2 document classes, and when I run the program i get an error, and I don't know how to fix it. It says "The class 'ball' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type."I don't understand why it isn't working now, is there some setting that I need to turn on to get it to work? I do have the line of code: import flash.display.MovieClip;
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]...
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?
super.zValue(n) should be super.zValue = n ........ wowy Nothing to see here folks, just keep moving on I'm having some difficulties in working with the as3 way of overriding methods.. specifically setters. I'm a recent convert from working with as2 for a few years, so some of these quirks are beyond me right now.Here are my two classes:class tempBase in package core
Code: package core { import flash.display.MovieClip; public class tempBase extends MovieClip
[code]....
I do not have any errors for the override of baseFunction, but on compile I get the error 1061: Call to a possibly undefined method zValue through a reference with static type core:tempBase.In as2, this would have been perfectly acceptable (even without the override function), and was incredibly useful in creating my class structures.
I've made a movie clip with buttons in it called 'myContent'. I want each button to reference a different video in the video player on the main stage. This movie clip is linked to a scrollpane, since there is not enough real-estate. I right clicked on the myContent movie clip in the library and chose 'export for actionscript' under properties.
[code]...
to get the scroll bar to work. When I add the script in the myContent movie clip to reference the different videos I get a few errors: 1152: A conflict exists with inherited definition flash.displayisplayObject.name in namespace public.5000: The class 'fl.controls.ScrollBar' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type. It seems I must tell the scroll bar to look in a subclass?When I get rid of the script telling it to load the videos, the scroll bar works and I get no errors, but when I put in the script to load the videos, its a major malfunction.
I have some classes: LowA, LowB, LowC, SpaceShip, that all subclass BaseChar. How can I instantiate one of the subclasses by using a string for the name. (I have been trying to get this to work for a couple of hours now). For example, the typical way that I have been instantiating the subclasses:
I'm playing around with some classes from my Learning AS 3.0 book in an attempt to understand them. I have a main (document) class, and a class called NavigationBarXML.
Because the buttons for the nav bar are all set up in the subclass NavigationBarXML, I would like to position the nav bar relative to the stage (think btn1.x = stage.stagewidth - 50) from within this class. I understand that you cannot deal directly with the stage from a subclass and that you must add it to the display list before you can reference the stage from within this class.
How would I set up the main class so that I can reference the stage from my subclass so that on browser resize, my nav bar is positioned relative to the stage?
Im in the progress of creating a XML menu component, and Im going well so far. My code is a bit messy and currently for the button press actions for the menu items I have done this below:(a method used by Senocular in the xml menu tute)
anybody knows how to make event listener for flash exiting? By mean exiting is when a tag that hold the flash object is removed so that you cant see the flash anymore...
i've made an xy pad that just broadcasts it's x and y positions as a percentage. i'm trying to abstract it into re-useable code, as per Lee's OOP scrollbar tutorial. i have got stuck trying to make an Event class for my XY pad, as Lee's example only sends one value and i would like to send two.. i can't see how to modify the code to send two values, surely i won't have to write two event classes for the x and y axis'?
I have an mp3 in a website, and i want that after the music as played for 11 seconds an image appears. So, can i make a trigger event in the mp3 so that after 11 seconds of playing the mp3, my image would show? I dont have the mp3 in the swf. It loads externally..
I made this file, test1.fla where a movieclip named mc1 contains two other mcs. Then I wrote some simple code to make the target of the event (in this case a mouse event) shrink a little.
Here's the code I've used:
Code: mc1.addEventListener(MouseEvent.MOUSE_OVER, onDown); mc1.addEventListener(MouseEvent.MOUSE_OUT, onUp); function onDown(evt:MouseEvent):void {
[Code]....
When I test this movie, only the selected mc that I hover is the one that shrinks, the other does not shrink (I am talking about those guys inside mc1). However I have done a similar file called test2.fla in which I replaced the nested mc's with shapes, the code is exactly the same, but in this case it's mc1 that shrinks, I mean no matter what shape I hover with mouse, both shrink.
I know (think so) that this is because of event propagation, but why do these two files react in a different manner? Is it becase the mc's inside mc1 can also be a display object container, but shapes cannot?
I am trying to figure out how to get access to a display object that was created in one subclass from a different subclass. Here�s my example: I created PnkRabbit.as and BluRabbit.as as separate classes (both extending RabbitTemplate.as).
I called them from Client.as (document class for Rabbits.fla) using an addRabbits button. Then I created MovePinkRabbit.as and MoveBlueRabbit.as (both extending Move.as which is listed as a protected var in RabbitTemplate.as). With this setup I can run Rabbits.fla and get a trace statement to come from MovePinkRabbit.as and/or MoveBlueRabbit.as, but I can�t figure out how to get access to the PinkRabbit and BlueRabbit movie clips from MovePinkRabbit.as and MoveBlueRabbit.as, so that I can actually move the clips. Here�s some of the code, (complete code and FLA in zip file).
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.