ActionScript 3.0 :: Class Hierarchy - Fields And Methods
Sep 4, 2011
I have a class1 in which I create a child from a class 2. Of course I can access class2 properties, fields and methods from class1. But is there a way to access class1 fields and methods from class2? Like to go a step back in the hierarchy?
View 1 Replies
Similar Posts:
Jun 9, 2010
I'm currently working on a tower defense game and am in kind of an odd situation. I've programmed it in such a way that a large class hierarchy is in place. It's like this StartScreen class ---> BaseLevel class ---> GUI class ---> TowerPlacer class(towers are stored in an array in this class) ----> etc.My problem is that i need to access an array in BaseLevel from my GUI class, is there any fancy trick for doing this? or have i screwed myself over.
View 2 Replies
Jan 19, 2011
I have a class linked with a movie clip, and in this movie clip I want to be able to add an event listener that calls a function in the Document class (the class you link with the fla as a whole). How can I do that? Say the name of my document class is KPScript.as. In my GameController.as class, I want to listen for key input and call pageChange() in KPScript.as when it gets called. Would I have to import KPScript.as into the GameController.as? If so, I wouldn't want to create another instance of the KPScript object.
View 1 Replies
Nov 9, 2009
Im making different quizes and small games. I always use a Document Class when coding, and usually i call this Main.as. Usually the Main.as contains pointers to different classes like:
private var _menu:Menu;
private var _messageBoard:MessageBoard;
etc..
My question/scenario is this: In for example _menu, i have a button that has an event listener on it (example: "Start" button). When this event is triggered (ie user hits "Start") I want to trigger a function in Main.as. How is the most elegant way of doing it? The solution i use now, is that i send a reference pointer of Main.as to each new class i make. ie in Main I would do something like this:
[Code]....
View 3 Replies
Jul 15, 2011
I m new for OOP concept see this is my class, How this class will return values???
[Code]...
View 2 Replies
Feb 22, 2011
I'm new to AS3. I've got two classes.
damnMoles.as and startBtn.as
The damnMoles class uses a method called randomPlay();
ActionScript Code:
public function randomPlay():void {
this.gotoAndPlay("moleLabel"+randomNumber(1, 18));
}
Which basically allows the looped mole animation to start from various points in its timeline. I could probably use a different method to do this using an interval variable, but I originally coded this in AS2.0 and I want to update it, to see how this are different.
damnMoles class is attached to 6 mrMole# instances on the timeline.
Originally I used code on the main stage timeline to start the animation of the moles.
ActionScript Code:
startBtn.addEventListener(MouseEvent.CLICK, startClick);
function startClick(event:MouseEvent):void {
mrMole1.randomPlay();
}
This works fine, however, I would like to refrain from timeline code and use .as files. My startBtn class looks like this, but I get the error:
1120: Access of undefined property mrMole1.
ActionScript Code:
package com{
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.display.Stage;
[Code] .....
So, how does this work? When I want to use a method from another class that has multiple instances on the stage?
View 1 Replies
Nov 22, 2010
I'm trying to call methods from a class to no avail. It just tells me that I have undefined methods.[code]
View 3 Replies
Dec 6, 2010
I need to call a method writeln() from the method buttonClick() which is in another class. Also need from a method of readResponse () method call loadSocket (str: String)
Errors:
Attempted access of inaccessible method writeln through a reference with static type main2.as$36:CustomSocket.
Call to a possibly undefined method loadSocket through a reference with static type Class.
Here is my code with 2 classes:
ActionScript Code:
package {
import flash.display.Sprite;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
[Code] .....
View 4 Replies
Jul 22, 2011
What if you have methods you want to use in your project, that really have no need of a class, or in other words, there is no need for an "object" associated with it. It's not going to have member variables, so why bother making it a class?
for example,
I want to create a randomNumber method, takes two numbers, low high, returns a random between or equal.
Originally in my code I had a very top level class i just called globalLibrary that extended movie clip, i put my randonNumber method there. Then every class in the project extended that. I got the method scoped properly, but to me it looks like a hack.
For example, the most basic functionality in flash like +, even = , trace, etc. Are these also methods defined in some class that we are extending? Or are they methods that have no object associated since that would seem to make just as much sense.
why can't I just create a file of methods, and import that file and have access to these methods?
View 7 Replies
Aug 16, 2007
SETUP: I have a MX2004 project where I'm attempting to pass a movie clip to a class, and have a method of the class act as the function for the onEnterFrame. PROBLEM: The class appears to lose reference to the movie clip when onEnterFrame() is called. TO DUPLICATE: Two files are needed, they are outlined below:
[Code]...
View 2 Replies
Mar 16, 2009
I need a way to reference to object (or the class methods inside). I have a button "Add box" and when it is pressed it creates a new instance of class "MyBox". The thing is everyone of these objects get the same name "box".Here's a hint of what it's like:
Code:
var arrBoxes:Array = new Array();
// var n:Number = 1;[code]...
Inside of the addBox function I can easily refer to the Object with just "box" (for example box.name = ..)but when in another function I cannot (and by then I might have created many "box"es).
View 4 Replies
Dec 18, 2009
If i instantiate class B (not a display class) in class A whats the best way to call some methods in class A from class B ?
View 3 Replies
Aug 5, 2010
Is there any way to add methods to the existing MovieClip class so that later I can use them everytime I instantiate a MovieClip? Something like this:
PHP Code:
package { import flash.display.MovieClip; public class myClass extends MovieClip { public function myMethod() { //do stuff } }}
Then, without instantiating myClass, I want to be able to call that method like this:
PHP Code:
var newMc:MovieClip = new MovieClip();newMc.myMethod();
View 4 Replies
Jul 7, 2009
i have a main movie. i use a loader to load a "example.swf" file. then i place that file inside a holder movieclip. in example.swf, i have an instance of a class i just wrote. this class has some particular methods. from my main movie, i want to call the methods of the instance of my class i have in example.swf. how can i do that??? i know it's a kind of casting, but none seems to work.
View 1 Replies
Oct 17, 2009
Here is the situation:I have created a movieClip named "tp_crack" on the timeline and created its class using linkage called "tp_crack".The tp_crack mc is like a small rectangle which breaks in 3 seconds when it is played.I have a seperate class in which I have used tp_crack to create many instances of tp_crack going by the names: cracked1","cracked2" etc.These instances are present in another movieClip (this time created within the class) called "crackContainer".Now I have added the following code to check for hitTest of those cracked1,2,3...... with a spaceship.The hitTest works but flash does not recognize the pieces as movieClips and does not play them as required, instead it gives me an error saying:1061: Call to a possibly undefined method play through a reference with static type flash.displayisplayObject.
for (var i:uint=0; i<crackedPieces; i++) {
if (crackContainer.getChildAt(i).hitTestPoint(Spacesh ip.x,Spaceship.y+(Spaceship.height/2),true)) {
[code].....
View 4 Replies
Aug 12, 2010
I have this base class
package sevengames.miranda.front.res {
import flash.display.MovieClip;
import flash.text.TextField;
[Code].....
I then, in the Flash document, create a movie clip which has this class set as the "Base class" in the properties. However, if I then do this.updateText(); in the movie clip's frame script, it complains
TypeError: Error #1006: updateText is not a function.
at miranda_fla::MenuButton_3/frame1()
Why doesn't it work? I know the class is read and compiled, because I had an error there which was reported.
View 4 Replies
Oct 11, 2011
Any good 'real world' examples of when and why you might use the map and filter methods of the new Vector class in Actionscript?
View 1 Replies
Mar 17, 2012
I am writing class that extends adobe air PNGEncoder,
I want to use the writeChunk method, but it seems to be private static and i cant seems to use it with my code But it gives the error as below
[Code].....
View 1 Replies
Dec 13, 2010
I want to add a custom method so that any MC can use it like this - Code:text1.fadeIn(2) - which would fade text1 in over 2 seconds. The actual method isn't important, it's the way to add it as a custom method for ALL MCs that is confusing me.I can add it inside the document class (that extends MovieClip) like{/*fade in over tt seconds etc*/};But pretty much everywhere I look peoples are choking on their coffee shouting not to use that method. So is there a nice, clean way to do it without using prototype?BTW I want to add these methods in a class that is imported into the main document class at compile-time. So my main doc class has code specific to this SWF but the general external classes like Effects and Transitions are imported as needed.
View 6 Replies
Jul 27, 2011
When I create classes, often I want to remove methods of the parent class (such as addChild(), perhaps), and I just override the method and have it throw an error. Is there a way to remove it completely?
View 9 Replies
May 30, 2005
I've got a custom class (using AS2) that mostly does things like set the score and level of a game, as well as sets the player's lives on the screen. I need to unload and attach MovieClips within the Lives control function, which require those methods from the MovieClip class. I don't think I need to extend this class from the MovieClip class, I think I need to import the class somehow. I don't know the path though..something like mx.MovieClip.
View 3 Replies
Nov 7, 2004
In AS2 we can not add methods n properties to built-in classes in the way we do in AS1. Like we would -say- write the custom "isNatural" method on the "Math" class as follows : * The following code is valid in AS1 but not in AS2
[Code]...
As the "Math class" is static internally. We know why we can not add custom methods n properties to every class, as the way we do in AS1. Later I came up with senocular' s very nice tutorial on OOP in AS2. And now i know how we can do it in AS2 style in an efficient n organised way. But i have a problem with the following code. It should not work ! but it does... * Following code is valid for both in AS1 and AS2.
[Code]...
View 5 Replies
Nov 5, 2008
does anyone knows the "time complexity" of Dictionary class methods ? for example, is the ""get"" is an o(1) time complexity ?
[Code]...
and another question in the same topic, how does the Dictionary "generate" an 'equal function' & 'hashcode' (assuming same implementation as in java's HashMap) from the object passed as a key? is it efficient ?
View 2 Replies
Apr 7, 2009
I have an urgent task to implement in my project code. I can't able to access the new properties and methods which are present in FileReference Class. For load() ,save() methods needs runtime version of Flash Player 10. I need to include the flash player 10 in CS3 publish settings Version. Otherwise you can suggest how i can able to access the FileReference class new properties and methods without CS4.
View 7 Replies
Mar 21, 2011
i have a document with objects in the library with the class Hitte, Kern, Ring and Ring_01 [to Ring_16]tge Ring_ pieces have a subclass of RingSegment.the code of RingSegment.as is as following. [code]....which should add a Hitte_mc to the stage, make it draggable , and make the Ring_ objects react to a hittest with the Hitte_mc. but I get tons of errors:
View 11 Replies
Dec 7, 2009
I have a class file named Main.as and another class called icon.as
package {
import icon;
public class main {
public var _time:String;
function main() {
[Code] .....
How do I get the current update from the main class without calling the MainObj repeatedly. Is this possible in Flash AS3, or any other alternate method for this idea.
View 2 Replies
Aug 27, 2008
Let's say I have a FLA file with document class called main. In main, let's say I have a method called test1 that just outputs "hello world" via trace. On the FLA I have a movie clip. In that movie clip, when the timeline reaches frame 123, I want it to invoke the test1 method (I just set up a simple action on the frame). However, I get an error saying that the method is undefined. I try this.parent.test1() too but that gives me the same error. Is it not possible to invoke a document class property from within the timeline of a movie clip that's on the stage?
View 2 Replies
Feb 9, 2009
I'm trying to access an init method I've set in one of my document level classes.
Container Movie loads Main Movie, which has Main.as as its document class, but I want to do a few things before I show the actual content. Here are some functions in Container.as:
Code:
public function moveLogo(e:TimerEvent):void{
loadTxt.visible = false;
var logoMoveUp:Tween = new Tween(logoCont, "y", Back.easeIn, 221, -250, 1, true);
[Code].....
If I trace e.currentTarget.content.init on my EVENT.COMPLETE callback function, I get "function Function()" like I should.
View 2 Replies
Jan 31, 2010
I've got a class (say ButtonBase) that extends MovieClip. ButtonBase has a method that names it ((this.)name = 'bb1') and adds it to the MainTimeline. Now I can see my extended ButtonBase MC on the MainTimeline. And if from a frame I write trace(this['bb1']), it returns an instance. The problem is that the instance is not recognized as an instance of ButtonBase. Suppose ButtonBase has another method, say testMethod(). Well, if I trace(this['bb1'].testMethod) from a frame on the mainTimeline, it returns undefined. If I trace(this['bb1'] is ButtonBase), > false I can attach a fla if you need it.
View 3 Replies
Jul 6, 2011
My question deals directly with ActionScript 3, although it could possibly appear in other languages. Consider the global trace function found in AS3. Calling the method requires no imports and is globally available from all classes.
class A {
public function A() {
trace("Hello, A!"); // Hello, A!
}}
Now, what if I create my own class method of the same name? In AS3, if I have a class method trace and then make a call to trace elsewhere in my class, the call is made to the class method over the global function. Essentially, I've blocked my ability to call the global trace method.
class B {
public function B() {
trace("Hello, B!"); // no output
} public function trace(s:String):void {
// do something else.
}}
Now, I know the obvious answer is to say, "don't create a class method called trace." But what if I'm unaware of the existence of the global trace function? Or what if I have a desire to "override" or "block" the global function? Is doing so bad programming? Or is this just another example of how AS3 is a poor object oriented language?
View 3 Replies