-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Okay let's get started
first... you may want to have a copy of this project, you can download, or clone this project for clone :
git clone git://github.com/alijaya/ressy.git path/to/your/directory
and then..., it has depedency, that is the hxJson2 library, so install this from haxelib
haxelib install hxJson2
and then... for embedding thingy, you want to install the "swfmill", just download it okay ;)
and then let's get started *oh i have say it already :p
okay... first let's make a new project, so let's create a folder, for example "RessyTest"
inside that... let's make default project file which are "Main.hx" and "compile.hxml"
and then, when use this library, you may want to make a folder for your asset, for example "assets" so in the "RessyTest" folder, there are :
-
assets folder
-
Main.hx
-
compile.hxml
okay... in the compile.hxml write like this
-main Main -swf9 ressyTest.swf -cp path/to/ressy -lib hxJson2
so far so good? great and in the "Main.hx", write like this
package ;
import ressy.Loddy; // if you want to use loader mode, import this
import ressy.Eddy; // if you want to use embed mode, import this
import ressy.Ressy; // import this on all occassion
class Main
{
static function main()
{
new Main();
}
public function new()
{
}
}
and then... we start from here :p
first add your resource (png, jpg, gif, mp3, txt, json, binary data) in your "assets" folder for your information, the extension is important, because from the extension the library know what type the file is.
for example add png file to the "assets" folder, and rename it "Image.png"
and then... when you download or clone "ressy", you will get the "loddy", "eddy", "ressy", "sample" sub folders. okay, in the loddy folder there is a "Loddy.n" file, it's a neko file. so in the terminal write like this
neko path/to/ressy/loddy/Loddy.n path/to/RessyTest/assets
and you will get the json file named "assets.json", the name of file is from the name of the asset folder if you open the json file, you will notice it has the information of the folder (parent-child)
have no error yet??? great :D
and then~..., in the "Main.hx", in the constructor, write like this:
Loddy.instance.load("assets.json", complete); // complete is a function
and add class method, named "complete"
public function complete()
{
// the resource have been inited, so do the main logic here
flash.Lib.current.addChild(Ressy.instance.get("Image")); // attempt to display the Image.png
}
so... let's try to compile, and open your swf... is it working??? great :D
okay... then..., there are something need to note:
-
when you use Loddy.instance.load("assets.json", complete); , the json file path must be relative to swf file, or you can use absolute path
-
Ressy.instance.get(something); , the parameter that we pass must be without extension, if you make another folder to your assets folder, it can be access with dot, so for example : you make a folder named "AnotherFolder" in your "assets" folder, and there are a image file named "Image.png" in your "AnotherFolder", so for accessing the Image.png, you want to write Ressy.instance.get("AnotherFolder.Image"); , it can be recursive.
-
So what type of object we get in Ressy.instance.get() ??? it depends what is the file extension, here is the list:
-
png, jpg, jpeg, gif, will be converted to Bitmap
-
mp3, wav, will be converted to Sound (wav type will not worked in loader mode)
-
txt, will be converted to String
-
json, will be converted to Dynamic (normal json converting)
-
another extension will be converted to ByteArray
-
...
okay then... next, we will try to embed the assets make sure the assets.json is up to date, if not, do like above. and then... in the ressy working copy, there are "eddy" folder, and in "eddy" folder there is a "Eddy.n" file, so write this in terminal neko path/to/ressy/eddy/Eddy.n path/to/RessyTest/assets
and you will get the "assets.xml" which is not so important, it is a file to make the swf with swfmill, but not used in our project, and you will get the assets.swf which contains our assets.
you want to modify your "compile.hxml" add this line
-resource assets.swf@swf -resource assets.json@json
yeah your right :D, we don't use swf-lib, we use Resource instead :D
and in the "Main.hx", change the constructor to this
Eddy.instance.load("swf", "json", complete);
the "swf" parameter is the reference to "assets.swf" resource, and the "json" parameter is the reference to "assets.json" resource and just compile :D
what??? we don't have to change the "complete" function??? yeah :D, the resource can be accessed with same function, it is Ressy.instance.get() :D and we are happy :D
so open the swf... working? hope so :D
okay... when we use loader mode, and when we use embed mode??? hmmm... i think, if it is still debugging, polishing, you want to use loader mode, it can be changed the graphic easily with only change the assets, and need no recompile and then use embed mode when it want to be released :D
so that is the basic of this library :D hope you enjoy it ;)