ADOBE/ ActionScript

[AS] 플래시 air 스마트기기개발 안드로이드, iOS 내에 package된 리소스 파일 file객체로 사용하기 관련

AlrepondTech 2020. 9. 21. 03:03
반응형

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

중요사항

여기에서 adobe air의 모바일기기에 대한 궁금한것을 찾아본다.

http://blogs.adobe.com/airodynamics/2013/03/08/external-hosting-of-secondary-swfs-for-air-apps-on-ios/

 

 

 

=================================

=================================

=================================

 

 

출처: http://jmsliu.com/469/load-flash-swf-into-ipad-application.html

Load Flash SWF into iPad Application

On November 14, 2011, in Flash Flex AIR, by James

Once Adobe released their Flex Air which enable flash developers to create IOS (iPhone & iPad) applications, it is possible to load the swf into iPad applications. But after testing from several times, I just find out it is not so good as what I thought. First, let me explain how to load flash into iPad application which is made by Air 3.0.

As Flash developers or Flex developers, we know that actionscript 3 allows us to load the external resource such as image, or swf file by using Loader in flash, or Image and swfLoader in Flex. The latest flash cs5.5 and Flex 4.5 can also let us compile our flash applications to IOS native applications. So this is the solution to load external flash swf by iPad application, creating a IOS native application by Flash cs5.5 or Flex 4.5, which is using Loader or swfLoader to load the external swf. There is a simple code snap in Flash:

package

{

    import flash.display.Loader;

    import flash.display.Sprite;

    import flash.net.URLRequest;

    public class PFIExternalSWFTest extends Sprite

    {

        public
        function PFIExternalSWFTest()

        {

            init();

        }

        private
        var loaderLocal: Loader;

        private
        var loaderRemote: Loader;

        private
        function init(): void

        {

            loaderLocal = new Loader();

            loaderLocal.load(new URLRequest("ExternalAnimatedSWF.swf"));

            loaderLocal.x = 10;

            loaderLocal.y = 10;

            addChild(loaderLocal);

            loaderRemote = new Loader();

            loaderRemote.load(newURLRequest("http://renaun.com/flex4/ExternalAnimatedSWF.swf"));

            loaderRemote.x = 60;

            loaderRemote.y = 60;

            addChild(loaderRemote);

        }

    }

}

Now let’s talk about what disappoint me a lot after I have several testing. In the native application what we create above, it works well to load a swf. But the swf must be a simple pure swf without any actionscript code inside, even for “stop()”, which means only the pure frame animation swf will work in this iPad applications. And it is totally useless because who will create such swf file without any actionscript code. I’m afraid that it’s time to shift to Html 5, Java or Object C programming, even Adobe itself already gave up the mobile browser flash player development.

 

 

=================================

=================================

=================================

 

 

 

출처: http://blogs.adobe.com/airodynamics/2013/03/08/external-hosting-of-secondary-swfs-for-air-apps-on-ios/

Starting with AIR 3.7, application developers will be able to host their secondary SWFs on an external server and load them on demand as per their application logic.

Till AIR 3.5, loading of only assets such as images, videos and SWFs without actionscript code, commonly referred as Actionscript Byte Code(ABC Code), from external server was supported. The workflow for the application developer for loading such assets from server resembles the diagram below :

 

 

 

 

With AIR 3.6, the feature for loading of locally packaged secondary SWFs containing ABC code was introduced. The detailed description about this feature and its usage can be found at this blog – “Packaging and loading of multiple SWFs for AIR apps on iOS“. The workflow for the application developer using this feature is described in the diagram below:

 

 

 

 

 

With AIR 3.7, the feature for external hosting of secondary SWFs has been introduced. The workflow for the application developers who want to use this feature would change slightly from AIR 3.6 and is shown below :

 

 

 

 

The developer needs to provide the url of the secondary stripped SWF in the URLRequest. The stripped SWF is obtained after the ADT packaging as described later in the blog post. A sample URL request for using this feature is :

private var externalSwfUrl:String= "http://www.xyz.com/ExternalSwf.swf"; private var urlRequest:URLRequest = new URLRequest(externalSwfUrl);

To use this feature, developer needs to specify a text file containing details of the SWF files to be stripped & externally hosted. This text file contains line separated paths of SWFs, which are to be externally hosted. A sample text file describing 3 SWFs to be externally hosted  would look like :

assets/Level1.swf assets/Level2.swf assets/Level3/asset/Level3.swf

The name of the text file needs to be mentioned in the <externalSwfs> tag within the <iPhone> tag in the application descriptor as shown below :

<iPhone> . . <externalSwfs>assets/SampleSWFInfoFile.txt</externalSwfs> . . </iPhone>

During command line packaging using AIR Developer Tool(ADT), the developer needs to specify the text file  just like an asset along with the set of SWF’s mentioned in the text file. A sample ADT  command for using this feature is:

~/bin/adt -package -target ipa-app-store -provisioning-profile <Provisioning Profile> -storetype pkcs12 -keystore <Certificate> -storepass <Password> ResultantIPA.ipa SampleMainSwf-app.xml SampleMainSwf.swf assets/SampleSWFInfoFile.txt assets/Level1.swf assets/Level2.swf assets/Level3/asset/Level3.swf

Or another variation of the above command is where all the SWFs to be externally hosted and the text file are present in the assets folder is as follows :

~/bin/adt -package -target ipa-app-store -provisioning-profile <Provisioning Profile> -storetype pkcs12 -keystore <Certificate> -storepass <Password> ResultantIPA.ipa SampleMainSwf-app.xml SampleMainSwf.swf assets

During IPA packaging,  ADT extracts the ABC code from all child SWFs, adds it to the final executable and generates stripped SWFs in the “externalStrippedSwfs” folder created in the current working directory. The directory structure within the “externalStrippedSwfs” folder remains the same as specified within the text file. The generated stripped SWF’s should then be externally hosted on a web server of developer’s choice.

NOTE: The “externalStrippedSwfs” folder is not generated in the currently available release of Flash Builder 4.7/ Flash CS6. To enable generation of Stripped SWFs for external hosting, command line ADT packaging should be used.

A sample actionscript code which loads a secondary SWF  from an external server is described below :

package { import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.IOErrorEvent; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; public class SampleMainSwf extends Sprite { private var externalLoader:Loader; private var url:String= "http://www.xyz.com/Level1.swf"; private var urlRequest:URLRequest = new URLRequest(url); private var ldrContext:LoaderContext; public function SampleMainSwf() { externalLoader = new Loader(); externalLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler); externalLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorHandler); ldrContext=new LoaderContext(false,ApplicationDomain.currentDomain,null); try { externalLoader.load(urlRequest, ldrContext); } catch(e:Error) { trace("Error ID : "+e.errorID+"\nError Message : "+e.message); } } private function completeHandler(e:Event):void { addChild(externalLoader); } private function errorHandler(e:IOErrorEvent):void { trace("In IO ErrorEvent Handler"); } } }

POINTS TO NOTE :

1. Conflicting symbols (classes and global functions) in all the packaged SWFs should be avoided, they might result into undesired behaviour.

2. The stripped SWFs generated using this feature are different from pure asset SWFs. It must be noted that while pure asset SWFs are valid SWFs the stripped SWFs are invalid SWFs.

3. The SWF version of the ROOT.SWF must be >= 20 to use this feature. If the SWF version is set to <20, the stripped SWFs won’t be generated in the “externalStrippedSwfs” folder even if the SWF files have been specified in the text file.

4. It is recommended that this feature should not be used as a means for updating and displaying content in a dynamic manner. The externally hosted SWFs should not be replaced by any other stripped SWFs except the ones generated during IPA packaging. Any change in the secondary SWF requires a corresponding updation of stripped SWFs on external server.

5. All the SWFs specified in the text file should be passed during the ADT packaging as well.

KNOWN ISSUES :

1. External hosting of Flex SWF does not work and might cause the application to crash.

 

27 Responses to External hosting of secondary SWFs for AIR apps on iOS

  1. Colin Holgate says:The article doesn’t answer the main question that people have asked:
    When the externally hosted swf is loaded, does it run as if it had its original code, or is it just artwork assets?
    A couple of other questions:
    Although it’s not recommended to use the mechanism as a way to update a swf, would that work?
    Can the externally hosted swfs be located in the app’s document folder, on the device?
  2. Reply
  3. March 21, 2013 at 5:16 pm
  4. Abhinav says:Hi ColinReply
    • Colin Holgate says:For number 3, my usage case was that you could perhaps move an online swf to the documents folder for offline use later. Like say you have a music player feature and you want the user to choose which large swf to load, the user would have to be online and do that large download every time the app is opened. If the swf could be cached in the documents folder it would only have to be downloaded once.
      • Abhinav says:Hi ColinReply
      • For such a use case you could write an application logic wherein you would first check the existence of the SWF in the application’s local storage, if it’s present there then you could load it from there itself.
        However if it doesn’t exist then you would download the SWF into the application & store a local copy of that SWF within the application for future use & then load it from the local storage itself. This way you will be able to use the external SWF hosting as well as reduce the users’ network usage as well.
      • March 22, 2013 at 7:18 pm
    • Reply
    • March 22, 2013 at 6:37 pm
  5. Below are the answers to your queries.
    1. The external SWF will work same as if it had the code in it. The only difference in the entire workflow is that the ABC code from all the secondary SWFs will be added in the final executable & just the assets part of the SWF remains in the stripped SWF after the packaging.
    2. It might work & might not work, please try it at your own risk.
    3. This would be same as the locally packaged multiple swf feature done in AIR 3.6. However, a point to note here is that if you try to load secondary SWF which has been specified in the text file for external hosting from the documents directory, then that file would be stripped and saved in the externalStrippedSwf folder and will not be present in the final executable file.
  6. March 21, 2013 at 5:35 pm
  7. CraigMurray says:Why is it not recommended to use this to dynamically update assets on the server and display them in an older version of the app? In Points to Note you state that but without any explanation as to why that is “not recommended”.
    • Abhinav says:Hi CraigMurrayReply
      • CraigMurray says:Ok thank you for the response. There is a big difference between “it’s dangerous, you might break your app if you’re not careful ” and “Apple might not like it”.
        • Abhinav says:In this case the former point is relevant. The behavior and working of the application after the updation of external SWFs cannot be defined.
        • Reply
        • March 22, 2013 at 5:13 pm
      • Reply
      • March 22, 2013 at 11:43 am
    • The reason for the recommendation is that your application might or might not work after the assets have been dynamically updated with newer assets. Hence, if you want to update the assets in the secondary swf(s), it is recommended to recompile the IPA with new secondary swf(s), replace the stripped swf(s) on server and then try to run the newly packaged IPA.
    • March 21, 2013 at 11:35 pm
    • Sergi says:I was wondering myself : how’s loading updated and code stripped SWF is any different from loading new version of image from remote server. Does every SWF carry some kind of unique hashtag or something? So when you compile your app, all swfs hashtags are encoded in the main swf and checked during remote SWF loading ?
      • Abhinav says:Hi SergiReply
      • Basically for every secondary SWF, during the IPA packaging the ABC code part of the SWF is moved to the final executable and assets part remain in the stripped SWF. However, when we try to load a secondary SWF which has been updated and then stripped in an IPA which just had the code part of the earlier version of SWF, if their is any difference from the code appended during the initial IPA packaging then the application won’t work. Even if it works, there is no guarantee that it would work seamlessly in the future.
      • April 9, 2013 at 5:08 pm
    • Reply
    • April 8, 2013 at 5:09 am
  8. Reply
  9. March 21, 2013 at 8:54 pm
  10. Viviana Baldarelli says:This is my question: I have a symbol in the assets.swf library and the symbol has a linkage name “symbolname” and its base class is a custom class “CustomClass1″. When I download the stripped assets.swf from the server, will I be able to access the library symbol by calling:
    getDefinitionByName (“symbolname”)?Reply
  11. OR is there another way to access symbols from the library of the assets.swf?
  12. March 22, 2013 at 6:01 am
  13. Leon says:Thank you. After 4 hours of tweaking, it worked!
  14. Reply
  15. April 3, 2013 at 12:24 pm
  16. cyberprodigy says:Generated SWF files are much bigger then non-stripped and when opened throws error VerifyError: Error #1042: Not an ABC file. major_version=0 minor_version=0.
    Any Ideas what might be causing it? I’m using AIR SDK 3.7
    • Abhinav says:The reason for the bigger stripped SWFs is the uncompression of secondary SWFs during the packaging process.Reply
      • cyberprodigy says:Thank you for explaining, Abhinav.
        Just to make it clear – should assets load fine in debuging mode, i.e. when passing -target ipa-debug to ADT?
        Do you also happen to know if it is needed also to compile swf file using 3.7, or only the packaging with 3.7 is what’s needed to load external swfs with this method?
        Regards.
        • Abhinav says:Yes, the assets should load fine in ipa-debug target.
          While the assets swf compilation is not restricted to any particular AIRSDK version, the Root SWF must have swf-version 20 for which you will need to use AIRSDK 3.7. Also, IPA needs to be packaged using AIRSDK 3.7 or later.
        • Reply
        • April 24, 2013 at 10:45 am
      • Reply
      • April 22, 2013 at 9:48 pm
    • As far as Error # 1042 is concerned, it is because the stripped SWFs are not a valid SWF files as the Actionscript Byte Code (ABC Code) is removed from these SWFs during ADT packaging. Hence these SWFs cannot be opened as it is in Flash Player. They would work fine when you try to load these SWFs within the iOS Application for which they are generated.
    • April 22, 2013 at 4:15 pm
  17. Reply
  18. April 22, 2013 at 4:04 pm
  19. Nathan says:Can someone post a real example? Everything I have tried does not work on an ios device.
    • Abhinav says:Hi NathanHowever, if you are still facing issues with making this feature, please feel free to clear out the issues which you are facing with this feature ?
    • Reply
    • The sample code written in blog post is a fully working AS3 code. Just create a new project using this code, update the URL of URLRequest to the one where you would be actually hosting the secondary stripped SWFs, package the IPA using the method described above, host the stripped SWF to the server which you mentioned earlier in your application and this feature should work fine.
    • April 24, 2013 at 10:28 am
  20. Reply
  21. April 22, 2013 at 10:06 pm
  22. bigger butt secrets says:I have read so many articles or reviews concerning the blogger
    lovers however this paragraph is actually a good piece
    of writing, keep it up.
  23. Reply
  24. April 24, 2013 at 3:51 pm
  25. Shay Pierce says:Does this solve the “Reloading a SWF is not supported on this operating system” error when attempting to reload a SWF on iOS?
    I need to be able to load in remote SWFs (which I can generate using this “stripping” method), but I also need to be able to reload them.
    • Abhinav says:Reloading of SWFs is still not supported on iOS and the same error would be visible when you try to load remotely hosted SWFs as well.
    • Reply
    • May 7, 2013 at 12:25 pm
  26. Reply
  27. May 6, 2013 at 10:19 pm
  28. Kenneth says:I would like to build an app using this type of packaging, but I would like to develop it for both iOS and Android. Does this work for android apps as well? Or is it even an issue for Android apps? Can Android apps load external SWFs with ABC?
    • Abhinav says:Hi Kenneth
      This feature is for iOS only. As far as Android apps are concerned, the loading of SWFs with ABC is supported for locally as well as externally. Hence you can simply load your secondary SWFs with ABC directly from external server, without any required stripping of SWFs.
    • Reply
    • May 23, 2013 at 11:56 am
  29. Reply
  30. May 22, 2013 at 11:22 pm
  31. Maximus says:Can i call methods from loaded stripped SWF? For example I need pass init params to loaded SWF, that has public method initParams
  32. Reply
  33. May 23, 2013 at 6:06 pm
  34. Greg says:Hi
    In the sample text file you provided there are 3 swf’s – levels of a game. In the game I am working on right now I have 40 levels, each with quite lot of graphics in it, and code ofcourse. I need to load the swf when it is needed and then unload (free the memory , GC) and load the next one. If user come back to the previous screen, the previous swf should be loaded again and the current one unloaded. It’s the common scenario in most games I have ever made Reply

  35. Is it possible with AIR 3.8 on iOS?
  36. August 6, 2013 at 3:23 pm

 

//---------------------------------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------------------------------

//기타 추가 설명

POINTS TO NOTE 에 3번 부분을 보면.

3. The SWF version of the ROOT.SWF must be >= 20 to use this feature. If the SWF version is set to <20, the stripped SWFs won’t be generated in the “externalStrippedSwfs” folder even if the SWF files have been specified in the text file.

이부분이 있는데 아래 프로젝트 -> 속성(properties) 에서 아래와 같이 설정해 주면 된다.

 

 

 

 

프로젝트 폴더안에 따로 distribution 이름의 폴더를 따로 만든다. 

 

distribution 폴더에는 기본 메인이된 .swf가 있고 따로 ios용으로 만들 assets 폴더를 만들어 서버에 두고 싶은 swf를 assets 폴더 안에

담아둔다. 그리고 변환 명령어가 담겨져 있는 bat 파일을 준비해둔다.

 

 

<iPhone> . . <externalSwfs>assets/SampleSWFInfoFile.txt</externalSwfs> . . </iPhone>

변환할 리스트 폴더들이 있는 파일 assets에 SampleSWFInfoFile.txt을 작성한다.

 

 

 

 

SampleSWFInfoFile.txt 파일안에 보이는 폴더 lv1, tb_test1, tb_test2, tb_test3 에 자신이

변환하고픈 swf가 담아져있다.

 

##############################################

"SampleSWFInfoFile.txt" 데이터 내용

 

assets/tb_test1/asset/tb_test1.swf

assets/tb_test1/asset/1_1_1.swf

assets/tb_test2/asset/tb_test2.swf

assets/tb_test3/asset/tb_test3.swf

assets/lv1/asset/1_1_1.swf

##########################################

위의 내용대로 폴더에 swf 파일들이 담겨져 있다.

 

 

그리고 아래와 같이 배치파일을 만들어준다. 배치파일에 들어있는 파일명칭은 각자 정하는대로고 일단 아래와같이

정하겟다.

 

그럼 아래 그림과 같이 폴더 구성을 참고하자.

 

 

 

 

 

change.bat

adt -package -target ipa-app-store -provisioning-profile ios_profile.mobileprovision -storetype pkcs12 -keystore ios_certi.p12  -storepass test00  test.ipa test-app.xml test.swf assets

 

여기에있는 "test.swf"와 "test-app.xml"은 프로젝트의 디버그로 빌드된 파일을 가져온 것 이다. 

그리고 위 그림에 test-app.xml 파일이 보이는데 이파일 내용에 debug 관련 문구를 모두 지워주어야 한다.

test-app.xml
0.01MB

 

여기 첨부 파일과 같이 될 것이다. (비교해가며 참고하면 된다.)

 

위의 파일 change.bat 를 실행시키면 아래 그림과 같이 폴더하나가 늘어난다.

 

 

 

그럼 ipa 파일을 애플기기(ipad, iphone등등) 에 인스톨 시키고 "externalStrippedSwfs" 폴더에 있는 파일은 서버쪽에 놓고 아이패드에서

인스톨한 앱을 통해 불러서와 (액션스크립트와 같이) 실행 시킬수 있다. 

 

 

 

=================================

=================================

=================================

 

 

출처: http://blogs.adobe.com/airodynamics/2012/11/09/packaging-and-loading-multiple-swfs-in-air-apps-on-ios/

 

Packaging and loading multiple SWFs in AIR apps on iOS

 

In AIR SDK 3.6 for iOS, there is a new feature that allows application developers to be able to package and load secondary SWFs that contain ActionScript byte code (or ABC) in their apps. Presently, due to certain restrictions on iOS, AIR on iOS requires that all the ActionScript code of an application be present in the main SWF or the root SWF. With this feature, an application developer can have ActionScript code in local secondary SWFs and package them along with the main SWF.

 

 

A bit of background

AIR apps on iOS can be compiled either in AOT (ahead of time) mode or Interpreter mode. To know more about these modes, please refer to an earlier post on this blog: http://blogs.adobe.com/airodynamics/2012/07/04/aot-or-interpreter/

The AIR Developer Tool or ADT has targets that lets you package apps either for the AOT mode or Interpreter mode. The targets for packaging in AOT mode are ipa-app-store, ipa-ad-hoc, ipa-test and ipa-debug. The targets for packaging apps in interpreter mode are ipa-debug-interpreter, ipa-test-interpreter, ipa-debug-interpreter-simulator and ipa-test-interpreter-simulator. In the interpreter mode, as the SWF is interpreted and not translated to native machine code, hence it runs slower than when in AOT mode. All developers are advised that whenever they publish their apps on the AppStore, they should make sure that they are compiled in AOT mode. To read more about the ADT command and the iOS package targets please refer to: http://help.adobe.com/en_US/air/build/WS901d38e593cd1bac1e63e3d128cdca935b-8000.html

This feature affects only the AOT mode targets and the behavior of the interpreter mode targets is unchanged.

Until now, AIR required that when packaging in AOT mode, all the ActionScript code of an AIR iOS app should be present inside the main SWF. Any SWF other than the main SWF, that is provided at the time of packaging, is added to the final application package (IPA) as a resource. Any attempt to load a SWF (local or remote) dynamically that contains ActionScript byte code (or ABC) using either Loader.load() or Loader.loadBytes,  resulted in an “Uncompiled ActionScript” error. A screenshot of the error dialog is below:

 

 

After the user dismisses the error dialog, the behavior of the application is “undefined”. Developers should never ship or publish an app in which the user may see such an error dialog.

Please note that if the SWF that is being loaded dynamically does not contain any ABC and contains only assets like bitmaps or audio, the SWF will be loaded successfully (even with AIR 3.4 and before). In fact, few developers have used this technique, to host asset-only SWFs on web servers and these are fetched only when needed. By downloading asset-SWFs on demand at run-time, developers have been able to reduce the size of their applications.

What has changed ?

In addition to the main SWF, the application developer can now provide a secondary SWF that contains ActionScript bytecode at the time of packaging and then load such a SWF dynamically using the functions provided by Loader. However, while dynamically loading a secondary SWF inside the main SWF, one needs to provide the application domain in which the secondary SWF should be loaded. The AOT mode in AIR on iOS does not support multiple application domains.

Below is a code snippet for loading a secondary SWF that is packaged with the application.

var _urlRequest:URLRequest = new URLRequest(“mySecondarySwf.swf”); var _loader:Loader = new Loader(); _loader.load(_urlRequest);

 

When the Loader.load() method does not specify a LoaderContext object, then by default, the SWF is loaded in an application domain that is a child of the loading SWF’s application domain. Multiple application domains are not supported in AIR on iOS, and hence the above code will not work on iOS and will result in the following error:

Error 3747: Multiple application domains are not supported on the operating system.

 

To overcome this error, the above code needs to provide ApplicationDomain.currentDomain as the application domain in the LoaderContext object. So the modified code is:

var _urlRequest:URLRequest = new URLRequest(“mySecondarySwf.swf”); var _loader:Loader = new Loader(); var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null); _loader.load(_urlRequest, _lc);

Loader.loadBytes

There is no change in the behavior of Loader.loadBytes() except for: In AOT mode, if the user attempts to load a SWF using Loader.loadBytes() and if the SWF version of the root SWF is greater than or equal to 19 (i.e. for the given build) then, the user needs to provide an application domain as part of the loader context which should be same as the root SWF’s application domain.

Loader.unload() & Loader.unloadAndStop()

The behavior of Loader.unload() and Loader.unloadAndStop() on iOS is below. When either of these functions is called the following will happen:

  1. The contentLoaderInfo property of the Loader object will become null
  2. Any assets that are loaded with the secondary SWF will be unloaded.
  3. Any references to AS classes in the loaded SWF remain in memory, and new objects of those AS classes can be created. This is different from the behavior on other platforms.

SWF Reloading

In AIR apps on iOS running in AOT mode there is a problem when a SWF is reloaded. Therefore reloading a SWF will not be allowed for AIR apps for iOS in AOT mode and attempting to do so will result in following error:

Error 3764: Reloading a SWF is not supported on this operating system

Note:If a SWF is accessed using different URLs like different paths referring to the same SWF, or using app:// and app-storage:// URI schemes to access the same SWF, then the two SWFs would be considered different and the SWF will be re-loaded. However, the behavior in such cases would be undefined.

Note: Reloading of pure asset SWFs will work with AIR 3.7 builds which can be downloaded from here

A bit about what happens behind the scenes …

The ABC code from the main SWF and all the secondary SWFs is extracted and placed in the main executable. The non-ABC parts of a SWF or assets in a SWF are kept inside the IPA (as assets). They are drawn in memory when explicitly asked using the Loader.load() call.

What will still not work?

1.Dynamically loading a ‘remote‘ SWF, that contains ActionScript code will continue to NOT work.
2.Embedding SWFs(having ABC code) using [Embed] tag will NOT work on iOS.

Where can I get the build?

The build with this feature can be accessed here

To summarize:

For locally packaged secondary SWFs:

  AOT (Ahead of Time) Mode Interpreter Mode
Local secondary SWF with ABC Earlier loading such a SWF gave the uncompiled AS Error.With this feature, this will work Works (unchanged)
Local secondary SWF w/o ABC Works (minor change required)* Works (unchanged)

For remote SWFs:

AOT (Ahead of  Time) Mode Interpreter Mode
Remote SWF with ABC Prohibited by Apple Prohibited by Apple
Remote SWF without ABC Works (minor change required)* Works (unchanged)

*The minor change is that when loading the SWF, the application domain should be the same as that of the main SWF i.e. ApplicationDomain.currentDomain.

Some FAQs

  • What is the loading order of ActionScript code among root SWF, secondary SWFs and ANEs?
    • The loading order is ANE, followed by main SWF, followed by secondary SWFs. This implies that if there is a class with the same name that is defined in the main SWF as well as the secondary SWF, then the class definition of the main SWF will be used.
  • Will I be able to load remote SWFs that don’t contain any ActionScript code?
    • As evident from the above table, the answer to this is YES.
  • Will I be able to use Workers API on iOS?
    • ActionScript workers is not supported on iOS. Worker.isSupported on Mobile (both iOS and Android) would continue to return false.

Points To Note:

  • Conflicting symbols (classes and global functions) in all the packaged swfs should be avoided, they might result into undesired behaviour.

 

50 Responses to Packaging and loading multiple SWFs in AIR apps on iOS

  1. Rob M says:Will the exact same code work on Android as well or will we need to do something different?
    • divij says:Yes the same code that works for iOS will work on Android as well. This functionality of allowing the loading of ActionScript bytecode from secondary SWFs is already present for AIR apps on Android.
    • Reply
    • November 12, 2012 at 11:27 pm
  2. Reply
  3. November 9, 2012 at 9:12 pm
  4. Pingback: tapzat » Packaging and loading multiple SWFs in AIR apps on iOS « AIR-o …
  5. Alan Lammers says:Hi Divij,Thank you very much in advance.Reply
    • divij says:The feature is available in 3.5.290 as well as in 3.5.460. It was disabled in a later build which is 3.5.520. If you face any issues with this build then do let us know.
    • Reply
    • November 12, 2012 at 11:24 pm
  6. Regards,
    Alan Lammers.
  7. We are working in a App that needs to load a secondary SWF with code, so this functionality is very importatn for us.
    The build you linked here is 3.5.460, but i think the correct build is 3.5.290.
    Could you please post the link to this build or send it to us by mail?
  8. November 12, 2012 at 9:03 pm
  9. Ed Guertin says:Very interesting to read about this as I have made a system to get around the no ABC code in external swfs problem. Maybe all my hard work is redundant if now AIR for ios can compile as3 code from a secondary swf! I am very confused though… in this article you said near the beginning:Then towards the end you said:Can the new AIR load external swfs with ABC or not?Reply
    • divij says:The second statement should read ‘Dynamically loading a remote SWF, that contains ActionScript code will continue to NOT work.’ Missed the crucial “remote”. Thanks for your comment.
    • Reply
    • November 14, 2012 at 12:21 pm
    • Jeff Ward says:Ed, it works for local SWFs – this means they need to be packaged in the app .ipa file (and hence ABC code is processed by the AOT compiler.) SWFs with code can’t be loaded from a server (remote, unprocessed).
    • Reply
    • February 18, 2013 at 11:48 pm
  10. Thanks very much if you have time to answer this.
  11. ‘Dynamically loading a SWF, that contains ActionScript code will continue to NOT work.’
  12. ‘Until now…. Any attempt to load a SWF (local or remote) dynamically that contains ActionScript byte code (or ABC) using either Loader.load() or Loader.loadBytes, resulted in an “Uncompiled ActionScript” error’
  13. November 13, 2012 at 3:23 pm
  14. Clint Modien says:Does this mean we can load one and only one external swf with abc bytecode in it?
    • divij says:No, you should be able to load any number of external SWFs with abc. You just need to provide all such external SWFs at the time of packaging (i.e. when running the ADT command).
    • Reply
    • November 14, 2012 at 12:16 pm
  15. Reply
  16. November 13, 2012 at 8:12 pm
  17. James Hunt says:Do instance names count as ABC or just actual Classes’s/AS Code?Reply
    • divij says:If you have any AS code then your SWF contains ActionScript bytecode. If you only have asset files like JPEGS or mp3s in your SWF files, even then the SWF will contain ActionScript bytecode if you have exported AS Linkages.
      If you unload and then reload the SWF, then the behavior would be random. In some cases it may even possibly crash your application. We are working on this, and it will be modified, when this feature is released in a future AIR version.
    • Reply
    • November 18, 2012 at 11:52 pm
  18. Also if you unload and then reload the same SWF with just instance names would this result in the “random behaviour” you talk about?
  19. November 15, 2012 at 8:07 pm
  20. Adam says:I am currently using one of the 3.5 beta sdk, and am successfully loading swfs with exported linkage ids and creating new instances of them based on those ids. Are you saying that the 3.5 final release I will not be able to do this?
    • divij says:If you have secondary SWFs that have exported AS linkages, and if you try load such a SWF, and you compile your app in AOT mode (for iOS), then you would get an “Uncompiled AS warning” error if you try with AIR3.5 final release or any of the previous AIR (final) releases. The same would not happen with the previous AIR 3.5 beta releases.
    • Reply
    • November 18, 2012 at 11:45 pm
  21. Reply
  22. November 17, 2012 at 5:03 am
  23. jian says:Could you explain more about the below statements, especially the first one?
    * Local secondary SWF with ABC + Interpreter Mode: Works (unchanged)
    * Remote SWF with ABC + Interpreter Mode: Prohibited by Apple
  24. Reply
  25. November 19, 2012 at 7:37 am
  26. John says:Is a Secondary SWF that contains frame labels and instance names considered a “Secondary SWF with ABC?”
  27. Reply
  28. November 21, 2012 at 12:44 am
  29. Kelsey says:Hi Divij,Why has this feature been disabled in the final release? Will it be brought back in future releases?
  30. Reply
  31. “The feature is available in 3.5.290 as well as in 3.5.460. It was disabled in a later build which is 3.5.520″
  32. November 23, 2012 at 12:27 am
  33. Ken Patel says:Is [Embed] supported or unsupported in this new feature?Eager to hear back. Thank you very much!
  34. Reply
  35. I am using the [Embed] tag to embed my secondary swfs. I installed the linked build of the AIR SDK, set my application.xml to reference 3.5, and added the -swf-version=18 option, but am still getting the ‘Uncompiled Actionscript’ warning dialog.
  36. December 3, 2012 at 4:55 am
  37. Miguel Santirso says:Hello, I was very happy to read about this until I saw this:If I understand correctly, that makes this new feature completely useless :S The whole point of loading multiple swfs is being able to load resources “on demand” and unloading them when you don’t need them.Reply
  38. The most obvious use case is a game in which the assets for each level are packaged into one .swf. Then you would load the assets when the player enters a level, unload them when he changes to a different level. But, obviously, I would need to reload the .swf of the first level if the player decides to play it again in the same session.
  39. “reloading a SWF will not be allowed for AIR apps for iOS in AOT mode”
  40. December 14, 2012 at 2:28 pm
  41. Gaius says:Hi,
    Can you confirm; I need to import SWF display assets, there is ABC in them (not from me, and I don’t use or need it). I had assumed that it was just stripped out and not used during release, but you are saying that there is an error dialog _even_ for release?
    Do you know if there is an option to expressly ignore and prohibit ABC so as to treat the SWF purely a an asset library?
    G
  42. Reply
  43. December 14, 2012 at 3:54 pm
  44. Jason says:I see that Beta 3.6 is out. Is this feature working and available in the beta version? Also does Android have any restrictions on loading remote swfs with actionscripting?
    • divij says:Yes, this feature is available in the 3.6 Beta. Please set swf-version as 19 to use this feature.
      There are no restrictions when loading remote SWFs on Android.
    • Reply
    • January 9, 2013 at 12:57 pm
  45. Reply
  46. January 9, 2013 at 1:58 am
  47. Yoyo says:Dear Divij,
    I try to embed SWF file with ActionScript to IOS application using Adobe Air. I use adobe air 3.6 and flash builder to load the secondary swf (existing SWF as an asset). On compiling I have added “-swf-version=19″, but still no success. The swf is loaded but not the ActionScript.
    This is my code :// Prepare the loader context to avoid security error
    var loaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
    loaderContext.allowLoadBytesCodeExecution = true;
    loaderContext.allowCodeImport = true;Reply
    • divij says:Are you using the “Embed” tag to package the secondary SWF in your main SWF? Embedding a SWF (with ABC code) will not work.Reply
    • However, if a secondary SWF contains ActionScript code, package it via the ADT command (without specifying the “Embed” tag). Also, do make sure to use namespace=3.6 and -swf-version=19.
    • February 28, 2013 at 7:25 pm
  48. // Load the SWF file
    loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onChildComplete);
    loader.load(urlRequest,loaderContext);
  49. var urlRequest:URLRequest = new URLRequest(“assets/secondFile.swf”);
  50. January 19, 2013 at 7:26 am
  51. talata_bao says:thanks, I have done but still a little buggy when I removeChild swf file and try to load the file is not.please help me
  52. Reply
  53. January 19, 2013 at 12:09 pm
  54. Julie says:It’s great application! If everyone is interested in, here are some adobe.com coupons code: http://sslash.com .
  55. Reply
  56. January 21, 2013 at 3:59 pm
  57. pqbao1987 says:Hi divij,var _urlRequest:URLRequest = new URLRequest(“mySecondarySwf.swf”);
    _loader= new Loader();
    var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
    _loader.load(_urlRequest, _lc);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompelte);
    function onLoadCompelte(e:Event):void{
    addChild(loader);
    }
    }
    btn.addEventListener(MouseEvent.CLICK,onCheck);
    function onCheck(e:MouseEvent):void
    {
    if(loader) removeChild(loader)
    }Reply
  58. when I removeChild and try reload “mySecondarySwf.swf” file is not,
  59. i’m using method:
    var _loader:Loader
    btn_load.addEventListener(MouseEvent.CLICK,onLoadSwf);
    function onLoadSwf(e:MouseEvent):void{
  60. January 22, 2013 at 10:45 am
  61. Andrea says:Hi,Thanks
  62. Reply
  63. i have install AIR 3.6Beta SDK to Adobe Flash Pro CS6 IDE and compile my iOS application that load external SWF but every time i finished to create .ipa i receive a warning: as code into SWF loaded externaly will not execute into iOS devices.
    What can i do to load externaly SWF? I don’t known how set swf-version as 19.
  64. January 31, 2013 at 6:04 pm
  65. Lorenzo says:What happens if I load a bunch of graphic SWF (no code) and then I unload them to save some space? How can I reload them consequently if I need to show that graphic again?
  66. Reply
  67. February 7, 2013 at 3:29 am
  68. Luiz Fernando says:Is this feature avaiable on 3.5.0.600?
  69. Reply
  70. February 7, 2013 at 7:26 pm
  71. Joshua Kernich says:Does this support the loading of nested swfs? i.e. Can a loaded swf load another swf?
    I have been able to get my main application to load 2 child swfs individually but when I have one of the child swfs loading the other, it doesn’t work. I get one progress event from the loader that tells me 0 bytes have been loaded (total bytes also traces correctly). Then the app appears to completely freeze. I am also using the same context object created by the parent swf with the same Application domain.
    • Nimisha says:Hi Joshua,Reply
    • Nested SWFs are supported and should work. Can you send a sample app (swfs, app-xml and source code)with which you’re facing this issue @nimisha1@adobe.com.
    • February 28, 2013 at 8:23 pm
  72. Reply
  73. February 20, 2013 at 10:10 am
  74. Pingback: (转)Adobe AIR读取本地外部SWF文件的功能概览 | 湖心小筑
  75. Alex says:I am using a system whereby any sounds that need to loop are kept in external swfs that I load on arriving at a screen and then unload on exiting the screen. I’ve just discovered that this leads to the problem of not being able to re-load the same swf if I later try to return to the screen. I get the error ’3764 – Reloading a SWF is not supported on this operating system.’
    Is there really no way around this? How does it know that I’ve loaded that swf before?
    • nimisha says:Hi Alex,
      1.How does it know that I’ve loaded that swf before?
      Ans: Runtime for iOS has been implemented like this where reloading of a SWF is prohibited.
      2.Is there really no way around this?
      The best way to deal with reload problem is that to not unload a SWF from your app instead just use/un-use it. I don’t know how you’re implementing things in you app’s SWFs but if the SWF is visible then then just make it invisible at the time of un-usage. To use this workaround you need to have different loaders for different SWFs.
      • Alex says:Hi nimisha, thanks for your reply. Regarding your suggestion of not unloading the swfs, the problem with this is that i would then quickly run out of memory on mobile devices. I wanted to use this functionality to allow me to load swfs that just contain audio (music) that I wish to loop seamlessly. If I kept each swf (and hence each music loop) in memory, uncompressed, it would use up all available memory.
      • Reply
      • March 21, 2013 at 4:13 pm
    • Reply
    • March 1, 2013 at 12:26 pm
  76. Reply
  77. February 25, 2013 at 9:52 pm
  78. tom says:I have problem too. CAN SOMEONE HELP PLEASE!
    I want to load and reload swfs. It’s not working with air3.6. When I test on PC it’s fine – work well I reload swf meny times. On iPad works only one. I can not reload swf. I put simple code. Can someone help me to fix it?var myLoaderSWF:Loader = new Loader();
    var mc:MovieClip;function initSkyview(e:MouseEvent):void
    {
    btnSkyview.visible = false;
    btnGround.visible = true;
    initSlide(“slide_skyview”);
    }function initSlide(_names):void
    {
    unloadSWF2();
    var _loadURL:String = “source/” + _names + “.swf”;
    myLoaderSWF = new Loader();
    //myLoaderSWF.contentLoaderInfo.addEventListener(Event.COMPLETE, loadSWFComplete);
    var url:URLRequest = new URLRequest(_loadURL);
    var loaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);//loadSWF is movie clip created on stage puted on layer
    loadSWF.addChild(myLoaderSWF);
    }
    function unloadSWF2():void
    {
    var mcSWF2:MovieClip = myLoaderSWF.content as MovieClip;Reply
  79. if (myLoaderSWF.content && mcSWF2.totalFrames > 1 && mcSWF2.totalFrames)
    {
    myLoaderSWF.unload();
    }
    }
  80. myLoaderSWF.load(url, loaderContext);
  81. function initGround(e:MouseEvent):void
    {
    btnSkyview.visible = true;
    btnGround.visible = false;
    initSlide(“state_sampt”);
    }
  82. btnSkyview.addEventListener(MouseEvent.MOUSE_DOWN, initSkyview);
    btnGround.addEventListener(MouseEvent.MOUSE_DOWN, initGround);
  83. stop();
    import flash.events.MouseEvent;
  84. March 1, 2013 at 6:48 pm
  85. Pingback: Packaging and loading multiple SWFs in AIR apps on iOS « AIR-o … | S60Aplicativos
  86. Kelsey says:In my application, I have a game that has many different themes. All themes share an almost identical codebase (including package and class definitions), but the graphics are completely different. In the Android version, I was able to load and unload the swfs successfully by loading them into a child domain of the Application.currentDomain. But for iOS, since they must be loaded into the ApplicationDomain.currentDomain, the result is that the first swf works fine, but thereafter, many of the graphics from the inital swf are being displayed instead of graphics from the new swf.
    Is there a solution to properly overriding the class definitions created from the inital swf? Or will I have to go into each swf and rename every class definition so they don’t conflict?
  87. Reply
  88. March 20, 2013 at 1:38 am
  89. Kev says:Hi,I tested each swf one by one, and they work fine, if they are the only swf in the bin folder, has anyone got any advice regarding this?
    • Kev says:Also, I’ve tried the external loading with air 3.7Reply
      • Abhinav says:Hi KevReply
        • Kev says:Hi AbhinavBut the first problem still exists, the swf version is 20, the packaging target is ad-hoc. On a side note, loading swfs seem to have a weaker performance than just including it as an internal swc library.regards,
          Kevin
        • Reply
        • The same problem persists, even when compiling them as local swfs. It seems as though only the first swf ( alphabetically) can be used, and no the others. Using any other than the first one will result in the game not loading anything.
        • Please ignore the second comment I posted, it seems to work fine when transfered to the iphone.
        • March 23, 2013 at 11:33 pm
      • Could you please confirm the following 2 things :
        1. SWF version of the Root SWF of your application ?
        2. The packaging target in which the IPA has been packaged ?
      • March 22, 2013 at 3:38 pm
    • The externally stripped swfs seem to generate the error 1042: not an abc file.
      Any clues on this too?
    • March 22, 2013 at 3:15 pm
  90. Reply
  91. I have multiple secondary swfs that requires loading, however, flashdevelop seems to only package only the first swf, hence the application will not run when other swfs are loaded and used.
  92. March 22, 2013 at 9:27 am
  93. Kev says:Just to add a little on the situation, using the loader to load the other SWFs results in the debugger prompting an internal debugger exception.
  94. Reply
  95. March 25, 2013 at 12:05 pm
  96. Nathan says:Hello,I’m using AIR 3.7 and I’m trying to load a local file. The file is a Captivate swf that shows the preloader when loaded, but does not load the rest of the swf.Thanks.
    Nathan
  97. Reply
  98. Any thoughts?
  99. I can get this to work when testing through the adl in Flash, but it does not work on my iPad..
  100. April 19, 2013 at 7:52 pm
  101. Pingback: Flash cs 5.5 embed - Flashforum
  102. biscito says:use loadermax and i’ll works fine,
  103. _assets = new LoaderMax({name:”mainQueue”, onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
    _assets.append(new SWFLoader(“LevelA1.swf”, {name:”levelA1″, context:new LoaderContext(false, ApplicationDomain.currentDomain, null)}));
    _assets.append(new SWFLoader(“LevelA2.swf”, {name:”levelA2″, context:new LoaderContext(false, ApplicationDomain.currentDomain, null)}));
  104. May 20, 2013 at 6:59 pm

 

 

=================================

=================================

=================================

 

 

 

플래시 air 스마트기기개발 안드로이드, iOS 내에 package된 리소스 파일 file객체로 사용하기 관련

출처: http://clack.tistory.com/235

iOS 내에 package된 리소스 파일 file객체로 사용하기

일단 사용하고자 하는 리소스 파일을 프로젝트 설정창에서 ActionScript Build Path항목에 있는  Source path 부분에 Add Folder해서 리소스파일들이 들어있는 폴더를 추가한다.

 

ActionScript Builde Packaging / Apple iOS 에서 Package Contents에 사용하고자 하는 리소스 파일들이 패키징 되어 있는지 확인한다.

var file: File = File.applicationDirectory.resolvePath("basicMap.html");

 

if( file.exists )

{

var fileStream:FileStream = new FileStream();

fileStream.open(file, FileMode.READ);

var str:String = fileStream.readMultiByte(file.size, File.systemCharset);

fileStream.close();

 

swv.loadURL("file://"+file.nativePath );

}

 

위 소스처럼 하면 basicMap.html 파일을 파일스트림으로 생성하여 string으로 읽을 수도 있으며

swv 라는 StageWebView로 html 파일을 로드하여 플래시 컨텐츠 위에 해당 html 페이지를 보여 줄 수 있다.

 

 

 

=================================

=================================

=================================

 

 

출처: http://renaun.com/blog/2010/11/loading-external-swf-with-packager-for-iphone/

 

Loading External SWF with Packager for iPhone

Posted on November 30, 2010 | 15 comments

This is not a very technical post but one to show that it is possible to load SWFs in iOS applications. Any actionscript in the SWF will not execute, my example is just a simple animated SWF. In this code example I have one SWF with a animated vector over 20 frames. I published it and put it next to my local project to be packaged up in the ipa and also put a copy on at renaun.com to test loading remotely.

Here is the source files on github.

Here is the application test file that loads an animated SWF called ExternalAnimatedSWF.swf:

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.net.URLRequest;
    
    public class PFIExternalSWFTest extends Sprite
    {
        public function PFIExternalSWFTest()
        {
            init();
        }
        
        private var loaderLocal:Loader;
        private var loaderRemote:Loader;
        
        private function init():void
        {
            loaderLocal = new Loader();
            loaderLocal.load(new URLRequest("ExternalAnimatedSWF.swf"));
            loaderLocal.x = 10;
            loaderLocal.y = 10;
            addChild(loaderLocal);
            
            loaderRemote = new Loader();
            loaderRemote.load(new URLRequest("http://renaun.com/flex4/ExternalAnimatedSWF.swf"));
            
            loaderRemote.x = 60;
            loaderRemote.y = 60;
            addChild(loaderRemote);
        }
    }
}

Make sure to include the SWF file in the PFI’s command arguments to bundle it with the ipa.

 

 

 

=================================

=================================

=================================

 

 

 

반응형