Actionscript 3 :: Getter / Setter Class & Scope In OOP

Feb 19, 2012

I recently completed a tic-tac-toe game in AS3, using some simple function-based code I had written in C many years ago.Now I'm on a quest to do it the "right way" using OOP techniques and best practices.Everything is now divided into neat little packages, it looks pretty, and the last part of my journey is to get all the little buggers to communicate with each other.I want to move the code which holds the game state from my main to it's own class in com.okaygraphics.model.GameState.The problem is nearly every other package gets and sets these game state properties.I'm trying to figure out the simplest way to encapsulate this stuff, while still allowing my other classes to access it.

1) Do I need a constructor? I mean, my program will never have more than one GameState. If I should call my getters/setters as instance methods, how do I get each other class to reference the SAME instance from their respective packages?

2) Do I even need getters and setters? Perhaps the class could just have 3 public properties? If so, how would I acheive the proper scope with regard to my other classes?

3) Should I assign everything to the class itself using the static keyword? If so, how would I implement and use those static methods?

4) Is this a mistake? Did I totally just program myself into a corner?

View 3 Replies


Similar Posts:


ActionScript 3.0 :: Custom Class Setter / Getter Are Blank

Oct 23, 2009

I have written a class, which is basically a textfield for forms. It will eventually have several validation modes built into it too, which will be set by setting a property of the object.anyway, my problem. Basically my setters are empty if the movie is used as a loaded swf within another movie.I have an Event listener within the class listening for the Event.ACTIVATE event (still not sure exactly what this does...) though i do know that i need this in place for the setters/getters to work.If i create objects from my class, set some properties everything is spot on, though the moment i load this working movie into another movie the Event.ACTIVATE does not fire.[code]Now, if i run this movie its perfect - everything works as it should, right down to the validation.however, this movie is to be used within another movie. When i load this movie into a parent movie my fields aren't added to the movie.

View 5 Replies

Xml :: Flex 4: Getter Getting Before Setter Sets?

Jun 3, 2010

I've created an AS class to use as a data model, shown here:

package
{
import mx.controls.Alert;

[code].....

View 5 Replies

ActionScript 3.0 :: Using A Getter/Setter Pair?

Nov 9, 2009

I'm having trouble updating a property value of a custom class (SubLoader) using a getter and setter. Inside the if() statement of the main fla you can see my attempt to set the percent value. Running a trace() method before the if() statement always outputs '0' for some reason. Tracing after the if() statment outputs an actual value. I can't figure out why the percent property always traces as '0' before the if statement even though I am updating it with each progress event.

[Code]...

View 3 Replies

ActionScript 3.0 :: Any Way To Make Static Getter / Setter?

Dec 29, 2009

Anyone know a workaround to make static getter/setters?

View 2 Replies

ActionScript 3.0 :: Pushing Value To Array Via Getter / Setter

Mar 22, 2012

I seem to have run into a situation where when I push a value to an array held within a singleton via a getter/setter , Flash seem so access the getter over the setter method. Within my command/controller (I am using RobotLegs)

override public function execute():void {
// various line of code here
//Place screenshot image into an array from model for later reference.
model.unitScreenshots.push(screenShot); // screenshot is just a Bitmap object
}

The getter and setter within my model e.g. robot legs singleton
public function get unitScreenshots():Array {
return _unitScreenshots;
} public function set unitScreenshots(value:Array):void {
_unitScreenshots = value;
}

When I set a break point on both the getter and setter, only the getter method is being called, why? I would think that a push value on the array would trigger the setter, not the getter.

View 2 Replies

Actionscript 3 :: Getter And Companion Setter In Different Namespaces?

Oct 11, 2011

I'm trying to create a property that can be set by extending classed and read publicly.I couldn't think of a good naming convention for a protected property with a public getter, so I tried to do this:

public function get name():String{ return _name; }
protected function set name(string:String):void
{[code]......

However I get the error (when trying to set name in an extending class): 1178: Attempted access of inaccessible property name through a
reference with static type testing:TestComponent.1059: Property is read-only.

If I change the setter to public, it works fine.

View 3 Replies

ActionScript 3.0 :: Difference Between Getter And Setter And Public Var

Jun 28, 2009

i dont get the advantages of using getter and setter instead of setting the var public.

View 7 Replies

ActionScript 3.0 :: Writing Getter And Setter Functions?

May 26, 2010

I have two functions one that sets and one that gets a number. The set one works, but the get one doesn't. I have it trace the set it returns the correct number, but when I set the getY function, it doesn't give me anything at all. When i took the number out of the trace it just gave me back only text. What am I doing wrong here?

ActionScript Code:
public function setY(y):void {
y = y;

[code].....

View 2 Replies

ActionScript 3.0 :: Accessing Getter And Setter From Timeline?

Mar 17, 2010

I have a .as file with class Main which contains:

Code:
public function set Set_AnimationFile(FileName:String):void
{
this.FileName=FileName;

[Code]....

How do i access these functions from my timeline script?

I have tried

[Code].....

View 4 Replies

Actionscript 3 :: Error When Using Getter/setter Methods On Sprite?

Nov 20, 2009

I'm trying to make a class that extends the Sprite, have some private properties attached to it and be able to read and write those properties using getters and setters. Simple... but the compiler throw this error "Access of possibly undefined property speed through a reference with static type flash.display:Sprite."It works if I set my class to extend the MovieClip object.Could someone explain me the logic behind this? why I can't use getter and setters with a Sprite?Here is a sample code:

package {
import flash.display.Sprite;
public class Vehicle extends Sprite{

[code].....

View 5 Replies

Actionscript 3 :: Error When Using Getter/setter Methods On Sprite

Aug 2, 2011

I'm trying to make a class that extends the Sprite, have some private properties attached to it and be able to read and write those properties using getters and setters. Simple... but the compiler throw this error "Access of possibly undefined property speed through a reference with static type flash.display:Sprite."It works if I set my class to extend the MovieClip object. someone explain me the logic behind this? why I can't use getter and setters with a Sprite?

[Code]...

View 1 Replies

Flash :: Property With A Public Getter And Protected Setter?

Sep 9, 2011

Is it possible to have a property with a public getter and protected setter? I have the following code:

public class Mob extends Sprite {
// snip
private var _health:Number; // tried making this protected, didn't work
public function get health():Number { return _health; }
protected function set health(value:Number):void {

[Code]...

I did have this.health -= dmg; but I split it out to get more details on the compiler errors. I don't understand how the property would be considered read-only within the same class. I also don't understand how it's inaccessible. If I make the backing field, getter, and setter all protected, it compiles but it's not the result I want; I need health to be readable externally.

View 3 Replies

Flex :: Getter And Setter Methods Versus Public Properties

Jul 27, 2009

Which is a much better practice in binding a value in Flex?

View 2 Replies

Flash :: Internal Setter With Public Getter Doesn't Work?

Jul 13, 2011

I have a problem whereby in AS3 using Flash Builder 4 using a public getter with an internal setter gives me the error "property is read only", like so:

[Code]...

View 4 Replies

ActionScript 2.0 :: "Getting" The Hang Of Getter/Setter Methods?

Feb 26, 2007

"Getting" the hang of Getter/Setter methods, but could use a review of my syntax. Does the follwing demonstrate best practices, meaning the least awarkward application of the technique?

Code:
// in Calculator.as
class Calculator {
private var _priceCD:Number;
private var _priceShocks:Number;
private var _priceCover:Number;

[Code]...

View 6 Replies

ActionScript 3.0 ::get A Function Pointer To A Getter/setter Function

Nov 28, 2009

The generally used workaround for this, is to use a regular function instead of a getter/setter.  This results in having to have ( ) after the function variable obviously.  The question is, can a Function variable be assigned to a getter/setter function and retain its attribute of not needing brackets.
 
Below is some Pseudo code representing the question:

######################################################### 
public class Foo(){
private var prop:Object;
public function get Prop():Object{return prop;}

[Code].....

View 3 Replies

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.0 :: Communicate An Object To Another Class With A Getter?

Nov 20, 2010

I have a document class .as file and I'm trying to communicate an object to another class with a getter. But it's nested inside another movie clip. The compiler says the movie clip it's nested in is undefined. Also, the moviecllip it's nested in is on the stage, dragged manually from the FLA LIbrary and has the instance name, gamelevel1 in the instance name box. I referred to it when I put the _player movie clip, which I'm trying to communicate with the getter, on the stage via and addChild method. Anyway here's the friggin' document class script:

package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;

[code]....

View 3 Replies

ActionScript 3.0 :: Can't Access Setter Function In The Same Class?

Aug 20, 2010

After doing nothing with AS for quite a while (2007) I started to code a little project in actionscript 3.0. An extensive Java course cleared up a lot on OO programming, but probably gave me some false expectations too.I'm trying to program a game in which a human and computer player compete. The computer player needs to do the same actions as the human one.So for every onClick for the human player has on a screen element, a computer player class needs the same functionality. Now for some reason the clickHandler won't let me call the setter function set selected function (see the lines in red).

Code:
package Classes{
import flash.display.*;

[code]......

View 2 Replies

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

ActionScript 2.0 :: Loadvar And Scope Variable - Array Seems Set To Null Or Out Of Scope

Jul 1, 2004

I add this actionscript code on the first frame. Variables are loaded but. The question is below the code.

[Code]...

View 2 Replies

ActionScript 2.0 :: Get Scope From Within Object/class?

Aug 24, 2009

Normally when creating small apps, i create a small object something like this.

Code:
//Example
var theApp:Function = function(){

[code].....

View 0 Replies

ActionScript 2.0 :: Class Variable Scope?

Jun 9, 2006

Take a look at this code:

Code:
import mx.utils.Delegate;
class Test
{

[code]....

Well... Doesnt work at all... In the class, there isnt a instance of i, so, how may i access this property inside a class function? But i still have an way to access the class.

I could do this way:

Code:
class Test
{
function Test(mc:MovieClip)
{

[code]....

But this way, doesn't sounds good

View 3 Replies

ActionScript 2.0 :: Scope When Extending Mc Class?

Feb 18, 2005

I have this extremely odd problem. OK to start off I have an MC in my library with the linkage identifier "Interface" and the AS2 class "Player" (both without "" of course). Now, my player class looks like this.

[Code]...

View 7 Replies

ActionScript 3.0 :: Top-level Scope From Static Scope Conundrum

Apr 2, 2010

I have a Debug class I've written, and I'd like to include a static trace() method in there, unfortunately I have no idea how to then access global / top level trace as effectively I've blocked it with the local static scope.[code]

View 4 Replies

Professional :: Scope Of Class Created In Flash?

Sep 14, 2010

What is the scope of a class created in Flash? If you create a class on the main timeline, can you use it anywhere in your project? If you use your class in a a movieclip, can you use that class outside of the movie clip?

View 3 Replies

ActionScript 3.0 :: Pass The Scope Of One Class To The Function Of Another

Oct 5, 2011

[Code]...

Specifies the value of thisObject to be used within any function that ActionScript calls. This method also specifies the parameters to be passed to any called function. Because apply() is a method of the Function class, it is also a method of every Function object in ActionScript. i don't get how "thisObject" is accessible from within the function invoked with it's apply method i'm trying to pass the scope of one class to the function of another so that the keyword "this" in the target function refers to the passed scope or am i misunderstanding the apply() method? it appears to behave differently between as2.0 and as3.0 as well, try this example code from the adobe docs

[Code]....

View 3 Replies

Actionscript 3.0 :: Parent Class Function Scope?

Feb 21, 2009

I have 2 class. Main class and a subclass (being an image loader).When the subclass has finished loading I want it to access a timer function in the mainclass.Code: Select all1)mainclass |> subClass.loadMe();2)   When subclass load finished.3)Subclass |> mainclass.startTimer();This i dont know how to do.

View 2 Replies

ActionScript 2.0 :: Losing Class Scope With SetInterval?

Aug 10, 2006

How do I fix this? With this code in my class:

function moveDelay():Void {
myInterval = setInterval(this.movePoints, delay);
}

I lose scope when it calls the function. "this" becomes undefined.

View 1 Replies







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