Influence values via update function


(Bimbamm) #1

Let´s assume I have a seperate Class for some variables:

public class Vars 
{
	public static var variableA:Number = 0;	
            public static var variableB:Number = 0;
}

Then I create a Class which extends an Entity

  public Class Ent extends Entity
{
public function ent(variableToChange:int)
{
            //code
 }
override public function update():void
{
     if(Input.mousePressed)
            {
                variableToChange++; // variable cannot be accessed
             }

In the MainClass I create an Instance of my Ent Classs

var newEntity:Entity = new Ent(variableA);


var newEntity2:Entity = new Ent(variableB);

My question is how can I change the values of variableA and variableB? The problem is that variableToChange cannot be read by the update function.


(David Williams) #2

The world code isn’t necessary. In your entity class, you can do Var.variableA because it is a public, static variable.