简体   繁体   中英

how to change properties of the constructor class from starling class

How do i change properties of the constructor class from a starling class I just added to it. or how do i call a function from the staring class that is a property of the mainClass

In my case how to change the alpha of an object in the mainClass of the FLA, from the starling class ( PuzzleGame ) and viceversa .

I have this:

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
    }

and

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
            }
        }
    }

The easiest way is to create a static method in your mainclass. something like:

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

or

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM