Trying to load local json file with createjs - json

I'm trying to load animations from Adobe Animate and it works fine when loading from a web server. But when loading from a local folder, I get "Access denied". The offending line is
loader.loadFile({ src: "images/1170_atlas_.json", type: "spritesheet", id: "1170_atlas_" }, true);
I should be able to simply include the contents of the file in a variable on the page and load the data directly. But I'm having problems finding the createjs function I need to call to load the spritesheet.Any ideas on how to do this?

You can not load JSON locally without doing some things like forcing Chrome to allow file access.
You can also get around it using JSONP, which loads the content as JavaScript.
If you want to manually load the contents, and embed your JSON in your page, you just have to make a new SpriteSheet manually. The EaselJS SpriteSheet docs have examples of this.
Cheers.

Related

Is there a good alternative for embedding a PDF with HTML next to using a local file path, online file path or data source as base64-string?

I am building a web app and I would like to show PDF files to my users. My files are mainly stored as byte arrays in the database as they are generated in the backend. I am using the embed element and have found three ways to display a PDF:
Local file path in src attribute: Works, but I need to generate a file from the database byte array, which is not desirable as I have to manage routines to delete them once they are not needed anymore.
Online file path in src attribute: Not possible since my files may not be hosted anywhere but on the server. Also has the same issues as the previous method anyway.
Data as base64 string in src attribute: Current method, but I ran into a problem for larger files (>2MB). Edge and Chrome will not display a PDF when I covert a PDF of this size to a base64 string (no error but the docs reveal that there is a limit for the data in the src attribute). It works on Firefox but I cannot have my users be restricted to Firefox.
Is there any other way to transmit valid PDF data from a byte array out of the database without generating a file locally?
You have made the common mistake of thinking of URLs and file paths as the same thing; but a URL is just a string that's sent to the server, and some content is sent back. Just as you wouldn't save an HTML file to disk for every dynamic page on the site, you don't have to write to the file system to display a dynamic PDF.
So the solution to this is to have a script on your server that takes the identifier of a PDF in your system, maybe does some access checking, and outputs it to the browser.
For example, if you were using PHP, you might write the HTML with <embed src="/loadpdf.php?id=42"> and then in loadpdf.php would write something like this:
$pdfContent = load_pdf_from_database((int)$_GET['id']);
header('Content-Type: application/pdf');
echo $pdfContent;
Loading /loadpdf.php?id=42 directly in the browser would then render the PDF just the same as if it was a "real" file, and embedding it should work the same way too.

Forcing SWF to load file in local driver of server before sending over browser

I am building a flash application which requires loading of an xml file using URLLoader. While developing application in my local machine with flash professional I can easily load it by
private var myLoader:URLLoader = new URLLoader(new URLRequest("./com/assets/config.xml"));
When I publish the application and click on the html generated and the app loads on browser perfectly.
If I make a server (localhost:1111) that delivers the html file over browser on connect, the html file doesn't load the application (.swf).
While trying to debug it, I found that if I change the myLoader variable as below, the html file loads the swf properly.
private var myLoader:URLLoader = new URLLoader(new URLRequest("http://localhost:1111/com/assets/config.xml"));
I believe the SWF is making another GET request after the html loads on my browser, that is the reason the SWF doesn't work without the change.
Is there any way I can load the xml file in SWF before it gets delivered over browser. This is to avoid another call to the server. I appreciate any help in clarifying my understanding and suggestion for workaround.
If you want to upload your SWF and have users access the configuration XML, you will need to host the XML somewhere reachable by your users. Your local machine (localhost:1111) is not reachable by anyone other than yourself (outside of some unusual hosts tweaking on the user's machine).
When you set up hosting and a web-server to actually serve the file over HTTP, you will need to do a few things:
Set up a crossdomain file on the server to define which hosts are allowed to load your configuration XML.
Amend your application to load data from the server, e.g. new URLRequest('http://your_domain_or_ip/config.xml').
The reason you cannot retain your reference to the XML file as a relative ./com/assets/config.xml is because the SWF will only load files over the local filesystem if it is being viewed as a file in the filesystem vs inside a browser.
When the SWF runs, the URLLoader instance you create will perform a HTTP GET to load your XML file.
If you want to avoid performing additional GET requests to fetch the XML, you will have to compile the configuration into the SWF itself using the [Embed] meta tag.

How to make html + flash graphics?

I've seen many websites using flash to render their graphics using dynamic data.
How can I do this to put in a user account page, where it shows some dynamic data?
The most common ways of getting external data into a SWF are:
You can pass data to an embedded SWF using FlashVars
The SWF can load XML or JSON data by loading a file from the server (using a Loader)

Load all images from internal application

I am trying to load all the .png files from an internal application folder into a list control and I am stuck on exactly how to do it. I have tried httpservice to get the folder and count how many images there are so I can loop through them but I just cant figure that out.
File structure
-src
-(default package)
-my application files
-icons
-all my .png files
httpService i tried:
<s:HTTPService id="loadAllImages" destination="/icons" result="gotImages(event)" fault="loadAllImagesFault(event)"/>
This always results in directory not found. Am I going about this completely wrong? Anyone have a suggestion?
You can't do this. To store an image within an Flash application (SWF or AIR), you must embed it either using #Embed('') in MXML or by using the [Class] method.
The only way to actually reveal a folder directory of an internal folder in an AIR app is by using File (which is an AIR only class).
var file:File = File.applicationDirectory;
file.browseForDirectory('icons'); ; //unsure if that will pull an internal folder or not, but you get the idea
If this is an external directory (doesn't sound like it is), I believe you would do it how you show in your question (although I have never needed to use this method, so I don't know if/how it works)

How to deploy SWF file?

I have a SWF file I created using Adobe Flex and I cannot seem to properly embed it inside an HTML page. If I take another SWF file and use it instead, it works all the time. My SWF file is pretty big (1 MB) while the other one is tiny (25 KB). However, I can wait 5-10 minutes and the server connection is super fast and it still will never load.
Is there something I need to do to the SWF to have it start up properly? My SWF almost never runs.
Thoughts?
I see two posible problems here:
Browser is not able to download your SWF file
You can check it if you add SWF file name directly into browser URL. For example http://your_domain/page/test.swf. If you will get "Not Found" error then your file was uploaded incorrectly
You did something wrong when embeding SWF file into HTML
If you have a working file then you can try to overwrite it with new one (leave original file name). Problem can be in sigle symbol in new file name, even letter case should match.
Or you can try using swfobject library for embeding flash into html