rizwin
rizwin

Reputation: 25

how to access variable from onother class

I have a class name project and project2

public class project1 extends sprite
{
    var window1:camera=new camera()
}

class project2 extends HomeUI implements IView
{
    var window2:camera=new camera()
}

i want to acces the variable window2 on class project1 can someone help

Upvotes: 1

Views: 47

Answers (1)

Pimgd
Pimgd

Reputation: 6043

In a method in project1, create a new project2, then just access it since it's public.

Example:

public class project1 extends sprite
{
    var window1:camera=new camera();
    public void doSomething(){
        var project2object:project2 = new project2();
        var window2:camera = project2object.window2;
        //and here you can do stuff with window2
    }
}

There's also a couple problems with your code - Namely that sprite needs to be Sprite... that project2 needs to be a public class... And I think the classes Project1 and Project2 should be capitalized.

Upvotes: 1

Related Questions