简体   繁体   中英

AS3 Accessing movieclip on stage from multiple classes

I have a fla file with a movieclip on the stage that is called "ding".

I have a Main.as file with the following code (in here i can trace ding.x):

package { 

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

public class Main extends MovieClip{
    public static var _goviral:goviral;

    public function Main() {
        createPlayer();
    }

    public function createPlayer():void{

        _goviral = new goviral();

        trace(ding.x);
    }

}
}

I also have a goviral.as with the following code (here i cannot trace ding.x):

package { 

import flash.display.MovieClip;
import Main;

public class goviral extends MovieClip{

    public var main:Main;


    public function goviral(){
        main = new Main();
        trace(ding.x);
    }
}
}

How can i trace movieclips from the goviral.as class? I have been banging my head against the wall to get this to work. Please help me!

tnx!

As @DodgerThud pointed out, you need to fix the infinite loop issue first. You can pass ding into the constructor of goviral so it has it's own reference to it:

package { 

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

public class Main extends MovieClip{
    public static var _goviral:goviral;

    public function Main() {
        createPlayer();
    }

    public function createPlayer():void{

        _goviral = new goviral(ding);
    }

}
}

You should not instantiate Main again.

package { 

import flash.display.MovieClip;

public class goviral extends MovieClip{    

    public function goviral(ding:MovieClip){
        trace(ding.x);
    }
}
}

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