ActionScript 3.0 :: Access The Document Class Directly With A Getter?

Oct 25, 2010

I am start developing small games (I have just finished reading a nice book from Rex van der Spuy) but I would like to use the best OO approach.Let's make a very simple example: suppose that i have a Player class which adds a listener to the stage waiting for keyboard events in order to move around the stage.I have also some enemies on the stage and the player must register a collision with them; what is the best approach in order to access the enemies on the stage and check for a collision with them on the ENTER_FRAME player's event? I have read a lot of solutions, but I am just starting coding and so I don't know which one is the best approach.

a) Access the document class directly with a getter (e.g. Main(root).allEnemies, supposing that every time an enemy is created it is added to the allEnemies array)?

b) A singleton class which has a reference to every instance in the stage?

c) I have read about using events, how?

ActionScript Code:
package 
{
import flash.display.MovieClip;[code].....

View 5 Replies


Similar Posts:


ActionScript 3.0 :: Access A Getter In A Class I Am Extending?

Apr 6, 2009

I am currently making a class called TiltVideo that extends BasicView (papervision3d).

BasicView has a getter function that returns a camera that I need to access.

View 3 Replies

Actionscript 3 :: Access A Displayobject On Stage In A Class That Is Not A Document Class?

Mar 7, 2012

How to access a display object on the stage in a class which is not a document class?

I am looking for a solution that doesn't involve passing the stage as a parameter to the class.

One solution i always come across is using "TopLevel.as". Is it a good method because as far as I have heard using global variables is not recommended because it might cause some problems while working on big projects.

View 1 Replies

ActionScript 3.0 :: Access A Movieclip On Document Class From Another Class?

Mar 3, 2011

Going further on my app, I felt in another problem. Despite having lots of posts on the web regarding this, none of the solutions worked for me In my document class (Main.as) ve two containers. One empty and another with a star that is being imported from the library. Here´s the main class:

package
{
import flash.display.*;

[code]......

View 4 Replies

CS4 Non-document Class Can't Access Library

Jan 27, 2010

Got two classes "Engine.as" and "Player.as". Engine.as is the document class that is calling Player.as.

The point is to have Player.as create a movieclip on the stage, but it seems it cannot access the library or something. Because when the player class is at the createHero() method it gives me the "error 1009 cannot access a property or method of a null object reference"

Engine class:

Code:
package test{
import flash.display.*;
import flash.events.*;

[Code]....

View 2 Replies

ActionScript 3.0 :: Access File Class From Document?

Oct 3, 2011

It seems simple, but it doesn't seem to be working I have 2 as3 files as classes "mainclass.as3 (this is the document class)" and GamePlay.as3

the GamePlay class works flawlessly on it's own, but when i try to create the var to access it ... var gp:GamePlay=new GamePlay(); ... i get the following error.

I have looked at tutorial etc, but i cant get it to work i am currently getting the following error.[code]...

View 1 Replies

ActionScript 3.0 :: Access A Mc Or Textfeild From A Non Document Class?

Sep 21, 2010

It used to be simple to access an object you put on the stage like a mc or dynamic text field by simply using _root.instanceName ect.  Now I see references to making references to the Stage and such like:
 
private var stage:Stage;
stage = stageRef; 
and I am still confused.
 
What I have going on is, I have placed a movieclip on the stage in Flash and gave it an instance name of Cell_mc.I have a cusom class that extends MovieClip with the following imports

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.EventDispatcher;

[code]....
 
This Class is tied to a set of MovieClips in my Library.

I have a listener: this.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
 
And a function:

private function pickUp(event:MouseEvent):void
{
this.startDrag();

[code]....
 
I get the following error whenever I try to access an object I placed on the stage from anywhere other than the document class:
 
1120: Access of undefined property Cell_mc.
 
How do I access the cell_mc that is already on the stage from this non-document class?

View 5 Replies

ActionScript 3.0 :: Access Some Vars From A Document Class?

Sep 30, 2009

if i want from a document class to access some variables in other classes (which are imported into that document class) does these variables need to be public to access them or they can be something else?

View 9 Replies

ActionScript 3.0 :: Access The Timeline From Document Class?

Nov 14, 2010

How do I access the timeline from the document class? I tried: trace(this.parent as MovieClip)

but I got a null object.

View 9 Replies

ActionScript 3.0 :: Access Document Class From Within Movieclip?

Jan 30, 2009

I was wondering if it was possible to access the document class from within a movieclip.

I am creating a slideshow type project, and I'm using a document class to switch between the frames using the arrow keys. However, in one of the "slideshow screen" movieclips, I want to have it stop, and then play another part when the arrow key is pressed again.

I tried to access my nextScreenToPlay method within the document class, but whenever I try to do it within a movie clip, I get this error: Call to a possibly undefined method nextScreenToPlay through a reference with static type class.

If I do a trace(Main), within a movieclip, it shows the class.

View 1 Replies

ActionScript 3.0 :: Access Document Class Var From Movieclip?

Sep 18, 2009

trace(MovieClip(root).TRACE);

so at pesent I am using this to try and access

Code:
public var TRACE:String

in the the document class.

however I am getting this

"1180: Call to a possibly undefined method addFrameScript.�"

my document class extends to Sprite as I have some stage resizing that occurs on Initialise

Code:
StaticInheritance extends Sprite

Im sure it has something to do with the way the document class extends.

View 1 Replies

ActionScript 3.0 :: Access Modifiers In Document Class

Jun 15, 2010

I tend to give my Document class all public access modifiers. Would there be any reasons not to do this?

View 3 Replies

ActionScript 3.0 :: Can't Have Access To Stage In Document Class

Aug 30, 2010

Just tried using cs5 on my new macbook and I have a tlf text object on the stage with an instance name of mText. I tried to access (mText.text = "test") it like this and got a null object reference. I tried to trace the stage from my document class and it was null when the tlftextbox was on the stage but i could trace stage correctly when I deleted the textbox. [code]...

View 2 Replies

ActionScript 3.0 :: Access Vars Between Document Class And Other Classes?

Apr 19, 2009

For the example, there's a single FLA with a document class "main.as." In the public class main.as package, there is a public variable: "var example:String='example';." Inside of the FLA, there is one movie clip in the library and it is assigned a custom base class "sub.as." The movie clip is then placed on the first frame of the stage so its constructor is run at runtime and reads the value of example.

What is the proper way to get the value of "example" in the root document class? Using "root.example" in the sub.as class to target the document class returns an error and when I trace "root", I get "null." Main.example naturally throws an error because that's looking at the actual class and not the movie / stage its attached to.The round-about way I've done it before is to dynamically add the object in the library and pass in the root path when I create a new instance of it (example: submc:sub = new sub(this); ).Is there anyway to get back to the document class with a built-in method like root, etc?

View 2 Replies

ActionScript 3.0 :: Access Stage Instances Outside Of Document Class?

Nov 20, 2010

I can access the targetObj instance inside the document class, but when I try to access it in another .as class,get this error:
 
Access of undefined property targetObj. 

View 9 Replies

ActionScript 3.0 :: Access Stage Property Through Document Class?

Jan 28, 2011

I m trying to access stage.width property but sometimes it trace 650 and 720 but i see my flash file dimension is 500x400, I need to align objects on stage..

View 1 Replies

ActionScript 3.0 :: Access Variable Within Fla File From Document Class?

Oct 17, 2011

I want to know how you access a variable within the fla file from the Document class?I want an int inside the fla or swf file to be accessed from the class that is being used to run the file?

View 5 Replies

Flash :: Access A MovieClip On The Stage From The Document Class?

Jan 7, 2010

I have a "box_mc" movieclip on the root of my stage and I need to select it from within my Document Class. I thought Stage.getChildByName("box_mc") would work, but it just returns null.

View 2 Replies

Flash - How To Access Stage Instances Outside Of Document Class

Nov 20, 2010

I can access the targetObj instance inside the document class, but when I try to access it in another .as class,get this error:
Access of undefined property targetObj.

View 2 Replies

Actionscript 3 :: Flash - Access Stage Outside Document Class

Jun 23, 2011

I am trying to add a keyboard event listener to the stage, to detect when a user clicks the left or right arrow keys. But this listener is called from inside a class file which is imported into the document class, therefore I think it doesn't know what "stage" refers to. How do I solve this?

[Code]...

View 2 Replies

Flash 9 :: Access Document Class Methods From Within MovieClip?

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

ActionScript 3.0 :: Direct Access Of Document Class Static Var?

Sep 19, 2009

I often write apps in flash where I wrap all the display elements into one parent display object container (not the stage). Let this parent container be mc_world for example. I declare this in my Document class (Main) as:

ActionScript Code:
public static var mc_world:MovieClip;

Since this container is unique and often times needs to be referenced from various classes in the project (that are not its children) I find myself often doing Main.mc_world across my project to access this container.

Is it bad practice to directly access static members of the Document class throughout my project? Are there any simple alternatives? I don't want to dispatch events every time I need to access mc_world. And using a singleton class doesn't seem all that different from the Document Class (which only has one instance right?).

View 0 Replies

ActionScript 3.0 :: Access Of Variables From Root Or Document Class?

Nov 13, 2010

Anyways, I've been trying to figure this out for quite some time.Let's say I have my document class. I'm guessing the document class can correspond to the first thing that gets run? (such as the "main" function in most C++/low level languages).If I set a variable in it:var myNumber:Number = 10;how would Iaccess: "myNumber" from other objects in my stage?Like a movieclip on my stage for example.If I go inside that movieclip into the movieclip's first frame, how would I say:trace(TheDocumentClass.myNumber);Another similar question is, what about the actual stage frame?If I click on frame 1 of my stage, set a variable:var aNumber:Number = 5;how would I access it from other objects?In my movieclip's first frame, what would I put?trace(root.aNumber); ?trace(stage.aNumber); ?

View 9 Replies

ActionScript 3.0 :: Access Public Var/functions In The Document Class?

Mar 27, 2011

How do I acsess public var/functions in the document class?

View 7 Replies

ActionScript 3.0 :: Access Input Field From Document Class?

Feb 27, 2012

Everything with my PurePDF project is in place I just need to be able to take user input and put it into the PDF document that is created.

If I have a text input field on the stage called inp_Name, how would I access the text the user puts into that from my document class which creates the PDF file and put that information into a variable in my document class?

View 1 Replies

Actionscript 3.0 :: Access Child Swf Document Class Using ApplicationDomain

Jun 22, 2009

i m getting an error, i am loading an external child swf file to main parent swf, and want to access the document class of the child swf through parent swf document class using application domain. Now when both child and parent swf resides in same directory it's works properly with application domain means we can access the document class of the child swf see the attachment samedirectory.zip and when we move child swf and it's document class to sub directory that time we are unable to access the document class of the child swf see the second attachment subdirectory.zip

View 1 Replies

ActionScript 3.0 :: How To Access Function In Document Class From Frame

Jan 15, 2010

Tried to access a function in the document class by simply calling it. For exampe, the code in my frame is:
Code: Select allinitButtons();
And in my document class I have the function:
Code:
Select allprivate function initButtons():void{
trace('anything');
}
But it gives me an error. Even tried to change private to public the same.

View 3 Replies

Actionscript 3.0 :: Access Child Swf Document Class Using ApplicationDomain?

Jan 17, 2010

i m getting an error, i m new to as3, actually i am loading an external child swf file to main parent swf, and want to access the document class of the child swf through parent swf document class using application domain. Now when both child and parent swf resides in same directory it's works properly with application domain means we can access the document class of the child swf see the attachment samedirectory.zip and when we move child swf and it's document class to sub directory that time we are unable to access the document class of the child swf see the second attachment subdirectory.zip and give me right direction

View 2 Replies

ActionScript 3.0 :: Access An Object That Has Been Made In A Class In An External AS Document

Sep 12, 2009

I'm using the following code to arrange indexes of objects on the stage the only problem is I can't access an Object that has been made in a class in an external AS document. if i go into the document and trace I can see it but i can't access it from the document class and arrange its index anybody have any ideas?

[Code]...

View 1 Replies

Access An Instance Reference To Document Class From Stage's Timeline?

Dec 30, 2009

Is there a way to get an instance reference to the document class to call a method of it from the stage's timeline?I see that here's a possible solution: using a singletonOther solution I though of is using stage.getChildAt( 0 ) but it's not very nice.Is there an 'official' instance reference? because the document class is obviously instantiated at startup, but is that instance accessible in any way without having to use a custom solution like the ones mentioned?

View 1 Replies







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