상세 컨텐츠

본문 제목

air 4.0 의 ios 기기의 swf 다운로드 후 로드 관련

스마트기기개발관련/IOS 개발

by AlrepondTech 2020. 9. 22. 03:13

본문

반응형

 

 

 

 

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

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

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

 

 

 

 

 

 

출처: http://www.eqsim.com/blog/?p=400

 

How I solved reloading codeless (w/o ABC) SWF files on iOS with Adobe AIR 4.0

By Jonathan Kaye | February 26, 2014

0 Comment

 

I have been working on an aviation training app with a great team at Pegasus Interactive. The app was originally done in Flash AS 2.0 using my state engine, then converted to work in AS 3.0 on iOS and AIR. One thing it does a lot of is load SWF files dynamically. We managed to get the app into the App Store in the middle of last year, while using AIR 3.5. We stayed with AIR 3.5 because AIR 3.6 introduced a restriction, namely that SWF files, even codeless ones (without ABC, or “ActionScript Byte Code”), no longer could be reloaded. Seems like this issue has been floating around since the latter part of 2013. For future updates, I was nervous, because caching SWF files would consume memory fast, and otherwise we would have to do a significant re-architecting of the app, such as allowing external loading SWF files attached to classes. So I went the easy route, waiting for 3.7 in hopes Adobe would solve the problem.

I saw a glimmer of hope when someone said it was fixed in AIR 3.7+, but that hope was shortlived. I had to face a more severe re-architecting future. The issue finally came to a head earlier this month, when Applestopped accepting apps and updates that used the older SDK’s. Whoops, we were going to have to get through this, now.

This post describes how we have successfully gotten to reload SWF’s (without code) on AIR 4.0, SWF’s we were downloading and SWF’s we had included in our initial distribution. In a nutshell, we needed two methods. The first method was for SWF’s we downloaded into the cache — essentially we got a file reference to it, and the reloading worked. Getting the file reference did not work when we tried to reload a SWF that we had packaged with the application–the second method added a URL variable to the loading, which then worked. I worked with Brandon Krakowsky on this, who helped a lot. I hope it can help someone struggling with this problem, perhaps seeing all the changes for 4.0 we needed to do!

Important: I have not submitted the app to Apple yet, so there is a chance they will reject it for some reason. If they do, I will update this post with that information.

 

Here are the issues we addressed:

  1. Getting a SWF to Load the First Time: Getting SWF’s to load at all, i.e., addressing changes that were made somewhere between AIR 3.5 to 4.0;
  2. Reloading SWF’s: Loading and reloading SWF files that were downloaded from the Internet; and,
  3. Status Bar Issue: Adjusting the status bar (top 20 pixels) text color on the screen — it was showing black, but our background was also black.

Getting a SWF to Load the First Time

The first time Brandon and I moved to AIR 4.0 and tried to load the first SWF (from the app:/ area, since it was packaged with the app), the SWF file did not load at all — it got an error about multiple application domains. We looked online to find this article about it, and solved the problem by adding the LoaderContext:

request = new URLRequest(path);
request.cacheResponse = false;
request.useCache = false;
_lc = new LoaderContext(false, ApplicationDomain.currentDomain, null);
moduleLoader.load(request, _lc);

You’ll also see here that we added cacheResponse and useCache options to URLRequest — I don’t know if this had an effect, but it seemed safest to use it.

After we had this, then at least we could load a SWF file (without ActionScript Byte Code, I remind you) — once.

Reloading SWF’s

We were first trying to load the SWF file that happened to be packaged with the app, in a folder called “modules”. Using the typical trick for loading web pages without caching, we appended a variable to the URL, which worked:

path = moduleDirectoryPath + module_folder + "/" + module + "?nf="+getTimer();

Then using the moduleLoader chunk of code above, it worked. If we did not have the variable at the end, we could load the SWF once, but the second time it gave us a “cannot reload SWF” error. Oddly enough, this happened with one of two of our SWF files — with one SWF file, it allowed us to reload it even without the appended variable. We never found out why.

After our initial success, we tried this with our externally loaded content, which we had of two types: (a) content downloaded into the cacheDirectory (hence a file pointer); and (b) content streamed from the Internet (http). We got an error trying the variable trick with our file pointer, because it could not find the file when it had the appended variable, like “file://filename.swf?nf=3322″. We were a bit stuck.

So on a lark, I removed the appended URL variable, and voila, the SWF loaded (and more importantly, reloaded). It also reloaded for our streamed content (item b, described in the last paragraph). I would prefer not to append the variable on the URL, to have a single approach for loading files, so I tried to get the content from the application folder into a “file” type of path to load, trying something like new File(File.applicationDirectory …) and the like. I got the correct file finally, but in the end, it gave me the reloading error. Very odd, so loading from applicationDirectory was different from loading from cacheDirectory, as far as I could tell.

So I took a step back and applied the dual approach:

if (loadFromApp) {
    path = moduleDirectoryPath + module_folder + "/" + module + "?nf=" + getTimer();
} else {
    path = moduleDirectoryPath + module_folder + "/" + module;
}

In other words, if I was loading the SWF from the applications/modules folder, I added the URL variable. If I was loading the SWF from the cache, I did not use it. So the path request to the loader was something like “/modules/…” if it was from the application folder (app:/), but it was “file://…” if it was from the cache). Here is the code to initially set the path:

var moduleDirectoryPath = "/modules/";

if (externalContent == FROM_CACHE) {
   moduleDirectoryPath = File.cacheDirectory.url + moduleDirectoryPath;
} else if (externalContent == FROM_WEB) {
   moduleDirectoryPath = "http://our-online-content.com" + moduleDirectoryPath;
}

and then it all worked fine!

Status Bar Issue

The last piece of the puzzle was handling the problem of the status bar text color — by default, it was set to black, but the background was black as well. Our app is not full-screen, so the status bar is showing. I needed to make the text color white (in addition to moving my graphics down about 20 pixels).

This change I made in the manifest file. However, we are using Flash CS6 to produce the ipa, and whenever I saved the iOS Settings, it would overwrite the manifest file! So my manual changes to the manifest file, to add the appropriate lines, kept getting overwritten. The final result (we’ll skip the pain), was to have my iPhone section as follows (note that our app is just for the iPad, hence the UIDeviceFamily setting):

<iPhone>
  <requestedDisplayResolution>standard</requestedDisplayResolution>
  <InfoAdditions>
    <![CDATA[<key>UIViewControllerBasedStatusBarAppearance</key><false/><key>UIStatusBarStyle</key><string>UIStatusBarStyleLightContent</string><key>UIDeviceFamily</key><array><string>2</string></array>]]>
  </InfoAdditions>
</iPhone>

The key was adding values for UIViewControllerBasedStatusBarAppearance and UIStatusBarStyle. However, when I tried to add them manually to the manifest, and then updating the iOS Settings in Flash CS6, the results came out wrong–Flash would absorb some of the keys and values, but not all. My solution from trial and error was to enter the following manually into the xml file:

<iPhone>
  <requestedDisplayResolution>standard</requestedDisplayResolution>
  <InfoAdditions>
    <![CDATA[<key>UIViewControllerBasedStatusBarAppearance</key><false/>]]>
    <![CDATA[<key>UIStatusBarStyle</key><string>UIStatusBarStyleLightContent</string>]]>
    <![CDATA[<key>UIDeviceFamily</key><array><string>2</string></array>]]>
  </InfoAdditions>
</iPhone>

Then Flash collapsed the CDATA’s when it wrote the file (after I saved the fla’s iOS Settings), into the final result (copied here):

<iPhone>
  <requestedDisplayResolution>standard</requestedDisplayResolution>
  <InfoAdditions>
    <![CDATA[<key>UIViewControllerBasedStatusBarAppearance</key><false/><key>UIStatusBarStyle</key><string>UIStatusBarStyleLightContent</string><key>UIDeviceFamily</key><array><string>2</string></array>]]>
  </InfoAdditions>
</iPhone>

Quite an adventure, to say the least!

Category: Adobe AIR Flash iOS app

 

 

 

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

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

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

 

 

 

출처: http://stackoverflow.com/questions/19536000/load-and-reload-external-swf-in-air-for-ios

Load and reload external SWF in AIR for iOS

i found several info on how to load one or more external SWF files, packaged with my AIR iOS App, the actual working code is:
It works on Android devices and on Windows PC, but on iOS it load the external SWFs only the first time! In my project I have several buttons that loads an external SWF, but each button works only the first time!
Any idea? It seems very unuseful if i can't reload an SWF!
Thanks, Nicola
ios actionscript-3 air swf
 

4 Answers

activeoldestvotes

If you can't load something a second time, perhaps it would be best to simply cache it and make a point of only loading it once?
 

Did you find this question interesting? Try our newsletter

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

 

A good way to handle this would be to load the SWF files into separate movieclips the first time and then when needing to "load" them anytime after that, just show those movieclips that already have the SWF files loaded in them.
 
You can't load a SWF file that contains any ActionScript ByteCode (ABC) then unload it and reload it on iOS. If you attempt to do this, the runtime throws error 3764.
 
I had problems loading SWF's even without code a second time. The solution I found depended on whether the code was from the application area (packaged with the app) or loaded externally (either from the web or downloaded into the caches folder). I wrote an extended post about here, if you're interested:http://www.eqsim.com/blog/?p=400 In a nutshell, here is my code for setting the path:
then here is my code for preparing the path, if the SWF is from the app area or otherwise (cache or web):
Finally, my loading statements:
and now I can load SWF's and reload them (more importantly). Of course the SWF's do not have bytecode in them.

 

 

 

 

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

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

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

 

 

 

출처: http://forums.adobe.com/message/6152802#6152802

SWFs not loading in Air 4.0... for iOS

Feb 24, 2014 1:29 PM

Tags: #air #ios #ipad #flash_professional

Hi,

I've read some of the posts about the problem of SWFs not loading in iOS.  This seemed to have to do with the SWFs having code.  We removed code from the SWFs and In previous releases, using previous SDKs (I don't remember the last one that worked) we had everything working.  But in the latest version compiled with the latest SDK (4.0...) none of the SWFs load.

 

of course I'm learning about this late in the game.

 

One more piece of information.  I did a test with an application that just loads one codeless SWF and have exactly the same result. 

 

If anyone has any ideas, I would be very grateful.

 

Best regards,

 

 

Chris McLaughlin

Translate

141 Views   1 Reply   Latest reply: Chris McLaughlin, Feb 24, 2014 7:24 PM

Was this helpful? Yes   No

 

Replies



  • Report






  • Thanks kglad.
  • Also from kglad's example: yourloader.load(yourexternalswf.swf,lc);
  • When I add the LoaderContext to the loader (at least with my experimental app) the SWF loads.
  •      var lc:LoaderContext=new LoaderContext(false,ApplicationDomain.currentDomain,null);
  • I borrowed this directly from a kglad response:
  • So code or no code external SWFs require a loader context.
  • Hi,
  • Feb 24, 2014 7:24 PM   in reply to Chris McLaughlin
  • 1.Chris McLaughlin,

 

 

 

 

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

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

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

 

 

출처: http://stackoverflow.com/questions/20451765/ios-app-using-air-3-9-how-can-we-reload-a-swf-that-was-previously-loaded

iOS app using Air 3.9 - how can we reload a swf that was previously loaded?

We are developing an iOS app using the air 3.9 sdk. Our application is such that we have 2 SWFs packaged inside the ipa file i.e.the main.swf and an experience.swf. The main.swf is loaded initially using application.xml. A button-click within the main.swf loads the experience.swf (which is located within the bin folder in the ipa, NOT remotely downloaded). This experience.swf contains assets and code.

When we create an ad-hoc build, experience.swf loads perfectly the first time, but if the user returns to the main.swf and then tries loading the experience.swf again, it doesn't load. Just the default stage color is visible. (This problem only occurs on the ad-hoc build. The debug build has no such issues)

To load this experience.swf we are using the flash.display.loader with loaderContext set as the ApplicationDomain.currentDomain.

mcExperience = new MovieClip();
var url:URLRequest = new URLRequest("ChristmasExperience.swf");
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);

loader.load(url, loaderContext);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, CompleteHandler);

addChild(mcExperience);

private function CompleteHandler(e:Event):void
{
trace("I HAVE LOADED .... SWF loaded... , waiting for the constructor call back..." + e.target.loader.content);
//mcExperience.addChild(loader);
mcExperience.addChild(MovieClip(e.target.loader.content));
//TODO : Set the Session ID Here
m_experienceBase.SetSessionID(int(m_ExperienceSessionID));
m_experienceBase.SetLocalPlayer(m_localPlayer);
//(loader.content as MovieClip).soundTransform = new SoundTransform(0);
//addChild(loader);
//setChildIndex(m_tfConsoleMsgDisplay, numChildren - 1);
}

When the experience is unloaded, we remove the holder MovieClip of the experience.swf and unload the flash.display.loader. This still does not re-load the previously loaded experience.swf.

if (mcExperience)
{
mcExperience.removeChildren();
removeChild(mcExperience);
mcExperience = null;
}

We are using swf-version=22 for both main and experience swf.

This is quite a big problem for us and we've gone through a bunch of posts, to help understand this issue better (a few examples below):

Is there any way to reload a secondary swf within an ios application?

ios actionscript-3 air swf loader

 

2 Answers

activeoldestvotes

Don't know if you checked here: http://blogs.adobe.com/airodynamics/2012/11/09/packaging-and-loading-multiple-swfs-in-air-apps-on-ios/
Basically you cannot reload an swf on IOS and this is from Adobe's mouth.
To overcome this, Adobe came with a NOTE: "Note: Reloading of pure asset SWFs will work with AIR 3.7 builds which can be downloaded from here"
Pretty lame if you ask me 
So what you must do? Well put the hole code as before in older air versions, in the first swf and use the second swf purely as graphic/animation resource.

While this is a big drawback, blame Adobe :D
 
Eventhough it says reloading of pure asset SWFs (SWF's w/o ABC) will work with AIR 3.7, I found problems with 4.0. I had SWF's with no code that did not work, and I needed a solution. I answered how I did it here: Load and reload external SWF in AIR for iOS and more fully here:http://www.eqsim.com/blog/?p=400

 

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

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

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

 

 

 

반응형


관련글 더보기

댓글 영역