Flash / AS3 protection - passing movieclip link to child swf?

I see strange behavior regarding the interaction between my instructors and the main application classes (all AS3 / Flash CS4). Roughly speaking, here's the flow of events:

  • Preloader.swf downloads two things: main.swf, which is the main application, and assets for a custom object consisting of text and images that are collected into the object by a preloader from different URLs.

  • When the download finishes, Preloader adds main.swf as a child. Preloader then calls
      init (myCustomObject) 
    to main.swf, where myCustomObject is a reference to the object assembled by the preloader during step 1, and
      public function init (customObject: CustomObject): void) 
    is the signature of the method in Main.as. (Preload.as passes * to the main object to be able to reference arbitrary functions without fear of compile-time errors.)

  • Main.as is actually a container for the application itself, so it creates an instance
      new Application (customObject); 
    following the link to the customObject assembled by the preloader and adds it as a child.

I installed thunderbolt so that I can log messages as the application launches, and this is what I defined. Creating the application object in step 3 causes problems; for some reason, the statement myMainApplication = new Application(customobj); in Main.as throws a beautiful error #1009 , which usually points to a reference to a null pointer or something like that.

The strange thing is that I added some entries to Application.as , and it seems that there is no problem with a link to customObject ; a call toString() in the customObject in Application constructor returns exactly the expected data.

In other words, the statement myMainApplication = new Application(customobj); in Main.as seems successful and unsuccessful at the same time. What gives?

+4
source share
5 answers

The reason myMainApplication = new Application(customobj); seems to succeed and fail at the same time, is that I did not quite understand how try/catch blocks work in AS3. A null pointer exception was thrown in a routine by the Application constructor, which occurs after the code in which Application checks to see if it gets a link to customobj. This error was captured by the try/catch surrounding the creation of the Application in Main , as it was the closest error checking code to be covered.

I hope my mistake saves someone else for doing something like this!

0
source

My assumption is that you are casting across application domains, so although the types are the same files, in the memory of each application domain they are two separate concrete types. There are many ways to get around this, perhaps by downloading to the child domain of the application, and not from the child domain, or not worrying about casting and explicitly calling this function on an untyped object.

WeLoveAppDomain should be useful if this is actually a problem. Can you put together the smallest possible example to demonstrate this failure so that we can deconstruct?

+1
source

Ensure that your global security settings in Flash Player allow local directory access.

Try it. Go to "Publish Settings" - "Local Playback Security" - select "Network Access Only." Flash CS4 by default is "Access only local files", which may not be pleasant. Hope this is helpful.

See: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/system/Security.html

0
source

I think we will need to see more code, but for starters: "customobj" ... where do you define this? You are still referring to "customObject". This is a missprint? If this exact status gives an error, then "customobj" will most likely be null.

0
source

Are you using FlexBuilder / FlashDevelop or the Flash IDE? Also, how do you configure your preloader?

If you are creating an application using FlexBuilder / FlashDevelop, have you set the beginning of the frame in the settings of your compiler?

0
source

Source: https://habr.com/ru/post/1299438/


All Articles