2

I'm new to AS3 and I am trying to access an instance of a frame from another frame. Here is my code.

package  {

    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import flash.text.TextField;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLVariables;


    public class Main extends MovieClip {

        var fl_TextLoader:URLLoader = new URLLoader();
        var fl_TextURLRequest:URLRequest = new URLRequest("questions.xml");
        var arrquestions:Array = new Array();//create new array


        public function Main() //main class call all the actions here
        {
            fl_TextLoader.addEventListener(Event.COMPLETE, fl_CompleteHandler);
            fl_TextLoader.load(fl_TextURLRequest);
            init();
        }

I am getting the error in this part, TypeError: Error #1009: Cannot access a property or method of a null object reference. I think it is because it is not on the same frame.

        private function init():void 
        {
            btn1d.addEventListener(MouseEvent.CLICK,play1d);
            btn2d.addEventListener(MouseEvent.CLICK,play2d); 
        }



        function fl_CompleteHandler(event:Event):void
        {
            var xmlData:XML = new XML(fl_TextLoader.data);

            //pass xml data to array variable
            arrquestions[0]=xmlData.q1;
            arrquestions[1]=xmlData.q2;
            arrquestions[2]=xmlData.q3;

            //load first question here
            q1.text = arrquestions[0];
        }


        function play1d(event:MouseEvent):void
        { 
            gotoAndStop ("questions2") 
            q2.text = arrquestions[1];
        }



        function play2d(event:MouseEvent):void
        { 
            gotoAndStop ("questions3") 
            q3.text = arrquestions[2];
        }

    }

}
Pimgd
  • 5,983
  • 1
  • 30
  • 45
user3349495
  • 369
  • 1
  • 3
  • 3
  • 1
    That is not possible - [a previous answer I provided on this topic](http://stackoverflow.com/questions/21182811/as3-accessing-frame-without-using-gotoandstop/21183791#21183791) should describe why in enough depth, but let me know if not. – Marty Feb 25 '14 at 06:11

1 Answers1

0

As Marty says, it's not possible. I'd recommend you get away from coding in the timeline as soon as you can. Working with external classes is a far more flexible way of working. It doesn't have to be too complicated; Link your Flash file to an external file and it's very similar to coding in the time line - except you CAN refer to objects that aren't necessarily on the stage.

moosefetcher
  • 1,841
  • 2
  • 23
  • 39