Recently I have done several experiments using javascript and HTML, but my code always seems a little messy. So I began to try some APIs to let the code a little better.
One of the best is the requireJS, but I don’t know if I am doing something wrong or if its the API that do not allow me to do somethings I think its essential.
So, I decided to make one loader that allow me to do the things I needed and its simple, so later I can change it and make it a little better.
The loader is made to use with Jquery, and you do not need to change de jquery file, you can just add it to the loader.
Here is the loader code commented.
// @author: Sharbel Freiberger
// @version: 0.1
// current item
var _atual = 0;
// array with the itens
var _itens = [];
// main function to load the file
// @param main: name of the main file to load.
// @param dependences: array with all the files to load.
function loadFile(main, dependences) {
_itens = dependences;
_itens.push(main);
loadItem();
}
// verify if there is another item in the array
function verificaProximo() {
if(_atual+1 < _itens.length) {
_atual++;
return true;
}
return false;
}
// function to use in the module files
// @param name: the name of the variable
// @param data: the data object
function define(name, data) {
window[name] = data;
}
// load and iten and insert it into the head of the page
function loadItem() {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', _itens[_atual] +"?nocache="+(new Date()).getTime());
if(verificaProximo()) {
script.onload = loadItem;
}
document.getElementsByTagName('head')[0].appendChild(script);
}
Here is an example of module file.
// define the function
// first define the name
// second add the object with all the data
define('file', {
dados: 'teste',
funcao: function() {
// you can access all the data using 'this'
this.dados = "test one";
$('body').append(this.dados);
$('body').each(function() {
// from within some funcions you can use the 'file' (name of the class) to access the data
file.dados = "test two";
$('body').append(file.dados);
});
}
});
Here is the Main file.
// the main function is the normal jquery loader
// it is the last to load
// and you dont need to create the functions.
// all functions you load in the html page you can access here
$(document).ready(function() {
file.funcao();
});
And the HTML file
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.2.min.js'></script>
<script type='text/javascript' src="loader.js"></script>
<script>
// add all the files you want to load
loadFile('main.js', ['file.js']);
</script>
</head>
<body>
</body>
</html>

This weekend happened the 23 Ludum Dare, its the 10 year anniversary, and I attended with an awesome game(at least for me, LOL).
The weekend was a lot strange, with many things happening at the same time, and I was without internet connection (now I am at a shopping mall), but at the end, everything goes well.
Here is the Ludum Dare Page
and here is the page for the game
if anyone want the source code, just leave me a message, and/or, if you find a bug, please, tell me.
I hope you enjoy the game as much as I enjoyed developing.
This is a very nice trick, that I think can be useful for everyone.
If you want to use the Facebook Connect AS3 but you can’t change the html page or can’t insert the facebook javascript into the page, you can use this and insert using flash ExternalInterface. the code is simple.
Read more…
After a long time with no updates, here is a new game.
Wheel of Fate is a game made for the Global Game Jam of this year.
This is the game I made for Ludum Dare 22.
The theme was Alone.
And goal of the game is to help the lonely flower to grow up.
Controls:
-Use the arrows or WASD to move.
-Use the mouse to shoot the birds.
-Feed the flower.
[EDIT]
If the flash fail. try this link. http://sharbelfs.com/blog/wp-content/uploads/2011/12/Main1.swf
[/EDIT]
You can download the Source-Code
This tutorial will be assuming you have a basic knowledge of the Smart Fox Server. Otherwise you can go to the site, install the Smart Fox Server, and take a look at the admin.
There are a lot of things you can do with the Smart Fox, and I will explain how some of then works.
First you have to understand how the server works. The Smart Fox Server basically just receive a message and pass it raw to the client, its like a tunnel for messages. All the data manipulation should to into the client. So almost always you will have 2 functions, one to send the message and the other to receive the message.
If there is something missing, leave a comment please.
Read more…
This article is actually divided in 2 parts. The PHP and the AS3.
I used the PHP to convert all the data from the KML into a xml with the encoded data for the AS3 to read easily.
The AS3 read the xml with the data encoded, create the poligons and render it into the map.
Here is how it works.
Read more…
I will try to explain in a simple way how you can create a private URL for download in CDN amazon Cloudfront.
The documentation in the website is a little difficult I think and I found some errors and there are almost none code examples. So this could help some peoples.
Here are the steps you have to do. Some of then are not described, but you can easily do it with the control panel of amazon.
Read more…
I don’t know if its really useful, but I used it last week because here I don’t really have access to a server to store my data, so, I saved the data in a json format and inserted everything into a PNG image.
Here I will show 2 functions, the one to convert from the string to an image, and the other to revert and transform the image back into the string.
If you are going to save the image into a file. You should save into a PNG file, I made some tests with JPG and none of them worked.
Read more…
This one is very interest, I think its because i couldn’t find something like this in the google.
There is a better example of this in the FWA, but I made a little different from them.



