S
S
Sasha_882022-04-08 18:40:27
ActionScript
Sasha_88, 2022-04-08 18:40:27

How can I access an instance drawn in Flash from ActionScript 3.0 in a document class?

Hello.
I can't do it in my main project. The project starts with a splash animation and stops at frame 178. Buttons are drawn in this frame in Flash. They didn't show up before. I did not complete the execution of the document class constructor. Now I organized the code in such a way that the buttons began to appear, but they do not work. There is a runtime error. The button instance at the time it is accessed is null. The event listener and handler are written in the document class. If their code is written in the frame where playback stops, then it works, but I want to understand how to do it in the main class. Why does not it work? I even made a small project on purpose to practice on it. Basically, it should be clear.
For example, I use the following document class:

package 
{
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.events.MouseEvent;
  
  public class ObjectExample extends MovieClip
  {
    public function ObjectExample()
    {
      addEventListener(Event.ADDED_TO_STAGE, addedResponse);
    }
    private function addedResponse(e:Event)
    {
      removeEventListener(Event.ADDED_TO_STAGE, addedResponse);
                        box.addEventListener(MouseEvent.CLICK, clickResponse);
    }
    private function clickResponse(e:Event)
    {
      trace("Нажато");
    }
  }
}

The mini project itself is 10 empty frames, only the button in the 8th frame. and also stop(); is also called in the 8th frame.
There is a binding of the Symbol of the button to AS.
625053c47ef1b571630906.jpeg
In general, if the project consists of only one frame or this button is placed in the first frame, then no error occurs, although in the second case the button still does not work.
Of course, you can place everything only programmatically, but this is somehow not quite right. What is the editor for then. I generally studied actionscript, but I don’t understand at all where exactly in the Flash document class the code is inserted. when it is written in the frames themselves. The same stop(). That's where? Why can't you just see all the resulting code? The Flash Player document class object also creates itself. I already talked about the constructor.
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question