如何从starling类更改构造函数类的属性

时间:2014-01-16 18:19:06

标签: actionscript-3 starling-framework

如何从刚刚添加到它的starling类中更改构造函数类的属性。或者如何从作为mainClass

属性的staring类调用函数

在我的例子中,如何更改FLA的mainClass中的对象的alpha,来自starling类(PuzzleGame),反之亦然。

我有这个:

public class MainClass extends Sprite
{
    private var myStarling:Starling;
    public var square:Sprite; 

    public function MainClass()
    {
        myStarling = new Starling( PuzzleGame, stage);
        myStarling.start();
        createAbox();
    }

    public function SendText()
    {
        trace("we are changing this in the main class")
    }

    public function createAbox()
    {
        square = new Sprite();
        square.graphics.beginFill(0x0000FF);
        square.graphics.drawRect(0,0,100,100);
        square.graphics.endFill();
        square.x = 100;
        square.y = 100;
        square.alpha = 0.5;
        addChild(square);
        square.addEventListener(MouseEvent.CLICK, onClick);
    }

    private function onClick(ev:MouseEvent):void
    {
        this.square.alpha = 1;
        //here how do i make the circle.alpha = 0.5;
            //circle is an object created in the PuzzleGame
    }

public class PuzzleGame extends Sprite
{
    public var circle:Image;

    public function PuzzleGame()
    {
        super();
        trace("you are in PuzzleGame");
        var s2:flash.display.Shape = new flash.display.Shape  ;
        s2.graphics.beginFill(0xff0000,1);
        s2.graphics.drawCircle(40,40,40);
        s2.graphics.endFill();

        var bmpData:BitmapData = new BitmapData(100,100);
        bmpData.draw(s2);

        circle = Image.fromBitmap(new Bitmap(bmpData));
        circle.x = 400;
        circle.y = 150;
        circle.alpha = 0.5;
        addChild(circle);
        circle.addEventListener(TouchEvent.TOUCH,onTouch);
    }

    private function onTouch(e:TouchEvent):void
    {
            parent.SendText();

        var touch:Touch = e.getTouch(circle);
        if (touch)
        {
            if (touch.phase == TouchPhase.ENDED)
            {
                circle.alpha = 1;

                //here how do i make the square.alpha = 0.5
                    //something like            parent.square.alpha = 0.5
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

最简单的方法是在mainclass中创建一个静态方法。类似的东西:

public static function get starlingInstance():Starling(return mStarling);}

public static function get mainClass():MainClass(return this);}