Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:20:11+00:00 2026-06-10T17:20:11+00:00

I have an iOS app that’s using AS3 and AIR. I have external swfs

  • 0

I have an iOS app that’s using AS3 and AIR. I have external swfs downloading from a server and playing properly–all of this works perfectly fine.

I don’t want the user to have to download these swfs every time they launch the app, though, so after the swf is downloaded the first time I want to save it to disk. That way I can load it from the local copy when I need it in the future, instead of downloading it again. I found this example online for saving files in AS3:

var file:File = File.applicationStorageDirectory.resolvePath("Swfs/" + "mySwfName" + ".swf");
var wr:File = new File(file.nativePath);
var stream:FileStream = new FileStream();
stream.open(wr, FileMode.WRITE);
stream.writeBytes(SWF_FILE_GOES_HERE, 0, SWF_FILE_DATA_LENGTH_GOES_HERE);
stream.close();

The problem is in the writeBytes line. The sample I found was for saving images to disk, and that line read like this:

stream.writeBytes(imageData, 0, imageData.length);

But I need to do this for a swf, not an image, and I’m not sure how to get the requisite data from my swf file. I’ve searched online for saving swf files, getting data from swf files, etc… But I haven’t found anything. I need to get the swf’s data and data length (I’m assuming this is a number of bytes?). Has anyone solved this problem before, or have a resource they can point me in the direction of?


UPDATE: Based on @LondonDrugs_MediaServices’ comments, I figured out the writeBytes line:

stream.writeBytes(mySwf.loaderInfo.bytes, 0, mySwf.loaderInfo.bytesTotal);

This seems to work, in as much as it compiles and runs without errors. But when I try to grab the file and put it back into a movie clip, I get this error:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

Which implies that the file was not, in fact, saved correctly. When I print the file locations, however, they seem to be right! When I save the file to the applicationStorageDirectory:

/Users/MyName/Library/Preferences/com.appdir/Local Store/Swfs/mySwName.swf

And the filename when I try and load it out of storage and into a movie clip:

/Users/MyName/Library/Preferences/com.appdir/Local Store/Swfs/mySwName.swf

This is the code I’m using to try and load it back into a movie clip:

var videoFileName:String = "Swfs/" + ENVAR.currentVideoSelected + ".swf";
var videoFilePath:File = File.applicationStorageDirectory.resolvePath(videoFileName);   
var inFileStream:FileStream = new FileStream(); 
trace("[Loading] filepath: ", videoFilePath.nativePath);
inFileStream.open(videoFilePath, FileMode.READ); 
var fileContents:String = inFileStream.readUTFBytes(inFileStream.bytesAvailable);   
inFileStream.close(); 

var req:URLRequest = new URLRequest(videoFilePath.nativePath);
var mLoader:Loader = new Loader();
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onVideoLoadComplete);
mLoader.load(req);

And my onVideoLoadComplete function contains these lines:

var myMC:MovieClip = e.target.content as MovieClip;
addChild(myMC);

But I’m getting that error 2044 and it doesn’t think the file exists. Can anyone spot the problem? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:20:12+00:00Added an answer on June 10, 2026 at 5:20 pm

    You can get the raw bytes of a loaded swf file by using it’s loaderInfo.bytes parameter. So for you example you could do this:

    var file:File = File.applicationStorageDirectory.resolvePath("Swfs/" + key + ".swf"); 
    var wr:File = new File(file.nativePath); 
    var stream:FileStream = new FileStream(); 
    stream.open(wr, FileMode.WRITE); 
    stream.writeBytes(mySwf.loaderInfo.bytes, 0, mySwf.loaderInfo.bytesTotal); 
    stream.close(); 
    

    Then to pull it back out into a MovieClip:

    var videoFileName:String = "Swfs/" + ENVAR.currentVideoSelected + ".swf";
    var videoFilePath:File = File.applicationStorageDirectory.resolvePath(videoFileName); 
    var inFileStream:FileStream = new FileStream(); 
    inFileStream.open(videoFilePath, FileMode.READ); 
    var swfBytes:ByteArray = new ByteArray();
    inFileStream.readBytes(swfBytes);
    inFileStream.close(); 
    
    var mLoader:Loader = new Loader();
    var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
    loaderContext.allowCodeImport = true;
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onVideoLoadComplete);
    mLoader.loadBytes(swfBytes, loaderContext);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iOS 5 App that consumes webservices from a Rails 3 server.
I have an iOS app that displays content from a sqlite db in a
I have an iOS app using In-App-Purchase that caters to an international audience, so
I have an AIR app that I am wanting to convert to a IOS
I have an iOS app that makes phone calls using the Telephone application by
I have an iOS app that connects to a server periodically looking for data
I have an iOS app that I'm migrating from the very slow and clunky
I have an iOS app which gets some JSON from a server (in the
I have an iOS app that I want to convert to using ARC .
I have an iOS app that streams background audio using AVAudioSession. It is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.