(AS3) How do I specify the path(s) to my assets? - actionscript-3

My directory structure is basically this:
Project Name (folder)
documentClass.as
class1.as
class2.as
bin (folder)
main.swf (default Output Location for flashdevelop)
lib (folder)
sounds (folder)
music.mp3
soundFX1.mp3
soundFX2.mp3
images (folder)
pic1.png
pic2.png
I am able to load the assets in lib/sounds and lib/images at runtime using
loader.load(new URLRequest( "../lib/images/pic1.png"));
and
music.load(new URLRequest("../lib/sounds/music.mp3"));
but cannot load them if I move my compiled .swf from its default location inside 'bin' up one level so that it's inside the Project Name folder next to the classes. I believe this structure is necessary when using additional files on Kongregate. (Am I wrong? I'm sending a zip file of the folder "lib")
I've tried various combinations: "../lib/images/pic1.png", "./lib/images/pic1.png", "/lib/images/pic1.png", "lib/images/pic1.png", etc., but I feel like a caveman poking a computer with a stick. I cannot find a definitive guide to how the "dot slash" navigation works.
Obviously, using the full path (c:/blah/blah...) is unacceptable.
Any help for me?

Related

Is there a way to change the path of multiple references in css/html at the same time? Problem with deployment due to no index.html in root

My website files structure is as follows: a folder for pictures, and a folder containing all my html/css files.
Now that I am trying to deploy my website for the first time (I'm using FireBase), it seems that I need an index.html in my public folder's root.
However, all my html/css files are in a folder, and my pictures in another. In order to pull out my home page and rename it to index.html, I would have to change the path & name of all the files that reference it as well (which is every file). Is there any way I can avoid this?
Thanks.
(My IDE is VSCode)
All content needs to be under a single folder, which is the one you then indicate in the public option in the firebase.json configuration file.
It is totally fine to have the HTML/CSS in one subfolder under there, and the images in another subfolder. But the entire public folder will be deployed, so you'll want to make sure you have no other files in there.
So this is fine:
public
html_and_css
index.html
main.css
images
image1.jpg
image2.jpg
image3.jpg
But here you can't just deploy all of src, as that would also deploy the code subfolder that contains secrete:
src
code
secrets_that_should_not_be_published
public
index.html
main.css
images
image1.jpg
image2.jpg
image3.jpg
If you have this last structure, you can tell Firebase to not deploy the code directory by specifying it in the ignore option in the firebase.json configuration file.

Distribution file source is different to development path source

I've started using a task runner to export all of my folders into a distribution folder using Gulp. The problem arises when I export images into the distribution folder, the path name is different from the one I'm using in my src file. So, as an example, when I target an image in HTML I type:
/assets/images/example.jpg
However, when the HTML file is distributed, it is supposed to target:
/images/example.jpg
It's still pointing to the assets folder, and creates a dead link. Should I be using a module like gulp-replace to automatically change these path names? Or should I just type in the assumed path name? Or, is there another method that I'm missing?
Sorry if I've phrased this badly, I'm working towards a new developer environment - let me know if I can provide you with any other details.
Should I be using a module like gulp-replace to automatically change
these path names?
Yes, gulp-replace will do the trick.
As an alternative you can place your index.html file into assets folder, so you don't need to change any paths when distributing the project.

How do I get access to assets added to a library?

I have a main project and an external library. I have added a directory of assets to the external library in src/assets/[50 files here].
When I do that, I go into the external library properties and select the folder and this includes all the files in that directory. Example shown (1 file selected):
In my main application I want to access that folder and copy the files into another directory. How do I access those files?
Note:
I may update these files periodically, copying the files and pasting them into that directory. There may be a few more or less files each time. So I'm against embedding them.
Go to your main project > Properties and select Flex Build Path. Under Source path, choose Add Folder... and enter the following
${DOCUMENTS}\GigaLibrary\src\assets
(assuming your library project is called GigaLibrary, that is)

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 Reconfigure Class File Paths In a FLA File?

I have a lot of library assets linked to external as3 classes. I would like to change the structure of the packages containing the linked classes, but if I do so, all links will get broken.
Is there any way to automatically or at least easily tell the FLA file where to get the new class files from? Could a FLA file be configured to read this sort of information from a configuration file?
You can add a folder to the source paths in ActionScript Settings. So if you had linked all your classes relative to the 'myClasses' folder, and then you moved everything to a different folder, you'd just have to update that one source path and it would find all the classes again.
Also, maybe this obvious, but I didn't realize it for a long time:
You can edit the class linkage right in the Library panel (without having to open the Properties for each symbol). Just double-click the linkage path.