Posts Tagged Flash

haXe, NME, RobotHaxe, Git, GitHub, brains exploded

Hell yeah! Crazy day. Spent all day figuring stuff out, now I’m pretty tired but I have to share my findings.

NME, a cross-platform solution

So, I am looking for a true cross platform development solution that will give me output for iOs, Android and Web (Flash). Using Flash and Air is too slow for me, but I do like ActionScript 3 a lot so NME seems like the logical solution. What is exactly NME? You know what? I don’t really know. It uses haXe and I think haXe is a programming language based on ActionScript. NME can compile both to Flash and C++ (and many more). That is as much as I could figure out, but I’ll keep digging.

Installing haXe and NME seemed pretty straight forward and it seemed to have worked, the only trouble I had was with FlashDevelop. Syntax high lighting is all off and it doesn’t seem to find where the classes are. But it compiles so I could at least get some stuff done.

From ActionScript to haXe

Actually that part isn’t that bad, there are little differences which you can find on this cheat sheet, but there are also concepts that are totally oblivious to me like the Dynamic type. But I just rolled with it and everything kept working, so this is something I’ll figure out later too. Little annoying thing every class needs a constructor (but at least the function name is only “new”) and if you extends something, you have to call super. Also, I noticed that on the NME Sprite (nme.display.Sprite), there is no rotationY property (well this is particular to NME, and I have never used rotationY before until 2 days ago, so I find this very funny).

On to RobotHaxe

Well I can’t really do anything without Robotlegs. I like how simple things are with it and well organized, so if I was going to move to another language, it needed to have Robotlegs. Period. Well I also need to be able to embed Fonts, have a Tweening engine and something to replace timeline animations, Robotlegs is the most important. Turns out there is a port to haXe called RobotHaxe made by David Peek. The only problem, there is no documentation, no examples, no tutorials… I decided to give it a shot anyway, how hard could it be? Kinda hard… haha. Anyway I got it to work, not sure it is the best way to do it, but it works (for what I have tested). I made this test RobotHaxe project using FlashDevelop and NME, not sure what it implies but I think it can be useful to people so I am giving it to you.

Git and GitHub

I never used Git before, always used SVN so that was new territory also. I also used to make a zip file and give my sources like that, but I figure GitHub is a better solution since you can browse before downloading. Anyway I put my test project on it. So go check it out here : Example RobotHaxe Project for NME and give me feedback or tell me how I could do it better, because I really don’t think it is perfect. But it is better than any other example out there. ( I know there is a bunch of guys using RobotHaxe for JavaScript, but the code I have seen from them wouldn’t work in Flash so it wasn’t really helpful)

, , , , , , , , ,

10 Comments


Optimizing Flash for the iPad

You might know that I am making a game for the iPad and it’s nearly done. The thing is, I also want to publish it on the web, you know, make money from sponsorship too. Actually, I think it might be the only way I make money with the game as the iPad app market seems really hard. Plus it will also cost me money to publish in the Apple app store (developer account), so I think I might be loosing money going that way. Anyway, I was testing my game for the web first and everything was working fine. I tested on the iPad after and that is when things started to get hairy.

Yeah, an iPad (iPad 2) is not a full fledged computer (funny to say this considering my first computer was a 486), so it is not as fast. Well I have seen some pretty crazy shit on the iPad, like the Dead Space game so I guess it can be pretty strong. This only means that the Flash player isn’t that great on it, probably because it doesn’t use the GPU. So as I was testing my game on the iPad, it started out working really great, but as the game went on, more and more objects got drawn onto the screen and that is when the performance started to go down. So I set out to optimize my code.

Object pooling

Object creation in Flash is an operation that is costly and since I hadn’t optimized anything yet, I was recreating every object on the screen every frame. There is a possibility of having 240 objects on the screen at the same time, so that’s a lot of object creating every frame. To minimize this, you can do object pooling, which is having a pool of already created objects and change their properties instead of creating new ones. I did just that and it went really fast to implement. The thing is, when I tested it on the iPad, it made no difference at all.

Blitting

Another thing that is heavy on the CPU in Flash is updating graphics, so I tried to optimize that part. Blitting is a technique by which you compress all your visual into only one Bitmap that you draw on the screen. So instead of having multiple display objects being redrawn (in my case 240), you only have one. Read more about blitting here. Blitting doesn’t fit well with every project (like those relying on vector graphics) , but mine was based on Bitmaps and didn’t have a lot of rotations (it did, but only 90 degrees one) so I could easily do it. I was pretty sure that this would help a lot, but it actually did nothing noticeable. I was a bit baffled here, maybe my redrawn zone is too big… It is a game for iPad so I have a full resolution of 1024 x 768, maybe that is too heavy for the Flash Player.

Code Optimization

So if it wasn’t the creation of objects or the graphics, than maybe it was the code. I had used Arrays everywhere cause it is just simpler to use than Vectors, so I changed them all. I also did some loop optimization and replaced some divisions by multiplications ( like /2 to *0.5). Also didn’t change anything…

Last Resort

My last resort was to change the game dynamics so that the game is less intensive on the CPU and that is the only thing that made any impact on performance. My game is a puzzle, so I removed 3 rows and 1 column from it thus reducing the possible maximum number of object on the screen (and also the redrawn region size, and probably also the number of computations) by 20%.

Conclusions

I’m pretty sad at this point, changing the game dynamics to optimize is not a really good decision, it’s kinda like saying let’s make the game less fun to make it run faster. What I liked about Flash is that I could compile for the web, iOs and Android with limited changes (in this case all I changed was different layouts based on size (height and width) of the game). Turns out it is not fast enough on iOs (iPad). Maybe when they put Stage3D on iOs that will do it, but till than there is no true cross development platform. I meant to look into Corona, but it does only mobile. And I really don’t want to fall into the HTML5 mess. I would really like to hear about a dev story about HTML5 and a game built for web and mobile and most importantly how much time it took to do.

, , , , , , , , , , , ,

7 Comments


Workin and playin

I have been working, on my projects and on paid work, and it’s been good. My own project is moving along fine and I should have something new to show pretty soon. As for work, well it’s going. I haven’t got much to write about, what about is mostly some little quirks inside of Flash Professional itself.

But I want to write about this little game I found: The binding of Isaac. I am pretty sure it was made in Flash and a demo of it can be found on Newgrounds. It’s a pretty well done game and it reminds me of the dungeons in Zelda and Kid Icarus. It’s got that same feeling, with upgraded graphics. The lore is also pretty funny, it’s got a really skewed sense of humor but everything fits and I find it very funny. Now the concept is really simple, but because they created so many power ups (each with their own hilarious visual) it makes it so that every run of the dungeon is different and it adds a lot of replayability.  Anyway, that is the kinda game I aspire to make. I advise you to go buy it on Steam, it’s only 5$.

, , , , ,

2 Comments


Flash’s future ain’t so bad after all

Back in February I wrote a post in which I stated that the future of Flash wasn’t so bright, well if you ask me what I think about that right now, I would say that it ain’t so bad. Why? Well, the roadmap for new features seems pretty exciting and also the array of stuff you can do with Flash is astonishing.

Molehill API (Hardware accelerated 3D)

After AdobeMax, I wanted to write a post just about this topic but I continually postponed it… but now it seems to fit perfectly with my second point so here it is. Molehill is some new low level API that enables some function calls to be hardware accelerated. Basically it permits some code to be sent to the video card instead of the processor, thus enabling us to do more crazy 3D stuff. Here is an example of what has been done with it and it is not even released yet:

If you’re a Flash Developer and this doesn’t excite you, I don’t know what will. Actually, I don’t think I looked forward so much for the next version of the player since I started using Flash. I started at FlashMX 2004, so Flash 8 gave us the filters and BitmapData; computers weren’t powerful enough to do the cool stuff with filters at the time, and I don’t know, BitmapData is pretty useful but I kinda didn’t know what I could do with it then. After that came Flash 9 with ActionScript 3, well that was nice but it took so much time for people to switch from ActionScript 2 to 3 that the excitement was kinda mitigated. Flash 10 was to follow with nothing really to offer… maybe Vectors are cool but they didn’t really impact anything. Flash 10.1? supposedly it is faster, doesn’t seem to be a game changer, the mobile stuff is cool but I wanted more for the web. Now Molehill is a very different ball game. Molehill will allow us to do way more than what we could before, both on the web and on the mobile. Gaming wise it is very easy to foresee how it will be used, but what I am mostly interested in is how it will be used for rich experiences, for rich internet applications or for data-visualization. It is the possibilities of this new technology to be used in unsuspected ways that makes it very exciting. Now, all we have to do is wait for it to come out. I bet you that the adoption rate will be very fast.

Flash everywhere

Maybe one of the good consequence of Apple saying no to Flash is everybody else saying yes to it to differentiate themselves. So yeah, Flash on a shit load of mobile ( Android, BlackBerry (PlayBook), Windows Phone 7), Flash on the TV (GoogleTV) and now Flash on the cloud (ChromeOS). It is seeing how easy it was to add a Flash app to the Google Chrome Web Store that made me realize that I was lucky to have liked Flash and have made it my job. I have so many possibilities now, from gaming to advertising (banner ads, ok I never want to do this again even if you threaten me with a gun), from website to mobile application, from your TV to the cloud. If you ever get bored as a Flash Developer there is still so many things you can do. So yeah, that did put a smile on my face and made me realize that Flash’s future wasn’t so bleak.

And to those who said that Flash would die, well it’s going to be goddamn hard to kill now on all these media… Cheers!

, , , , , , , , , , , ,

7 Comments


I am Flash Developer

This isn’t the next article I wanted to write but it was on my list since Flash In The Can Toronto (2010). It comes from all the talks surrounding the refusal from Apple to let Flash on the iPad ( i guess we can just say iOs now).  During that period a lot off people (including me) where uncertain about their future. I mean when someone as powerful as Steve Jobs tells you that your job shouldn’t exist, you think about it twice. Out of the turmoil that ensued, some voices touched me more than others. What they were saying is that they, as developers, weren’t tied to a technology and that if Flash was to disappear tomorrow, they would still have a job. That got me to think. A lot. The next thing that affected me was something I heard at FITC concerning designers. How they don’t call themselves ’Photoshop Designers’ or ‘Corel Draw Designer’ (I tried to think of another product than Adobe but just could come up with Corel Draw (who uses that anyway), but you get the idea). I think this follows a bit the same vibe as the comments from the Flash dudes.

All of this feed my reflexions, I mean I have tried a lot of technologies (all things in perspective, I am still at the start of my career, so I humbly say so). I have tried Java, PHP, MySQL, C, Flash, ActionScript 2 and 3, HTML/JavaScript/Css, Ajax, Asp, C#, Python. And you know what? There is nothing I like better than doing ActionScript 3. I mean the tools help a lot; FDT (yes I said it, I now like FDT) or FlashDevelop for code and Flash CS5 for visual assets. I like the workflow, I like making PSDs alive, I really like using TweenLite to make stuff move, I like figuring out how to build my applications so that they minimize load time and CPU usage (I also like maximizing CPU but don’t tell HTML5 fanatics, they know jack shit about pushing limits, yet, but they will know what I mean when they taste it, which will happen for sure). All of that I can’t get from any other technology to the extent that Flash does it right now.

It’s been 2 months that I am at B-Reel right now. I really love it, but the project that I am doing right now mostly doesn’t involve Flash ( I managed to stick a bit of Robotlegs in there) and is mainly Javascript/Html/Css. I really look forward to doing a Flash project. I really don’t want to do html ever again. I don’t have fun doing it (well I am just speaking about the technology, the project itself is amazing). Also, I feel the world of Flash is so deep and there is so much you can do to get better that if you learn all of the other technologies you can never get truly as good on the Flash Platform as one could be. For all of these reasons, that is why I am Flash Developer, that is my title and I am not ashamed or feel diminished by it. It really defines me.

With that being said, it gives me security. I think I am not alone in this situation. I think Flash gives a mean to express themselves to a lot of people and because of that, you can be sure that these people will produce tons of cool shit with it. And other people will want to see that cool shit. That gives a reason for Flash to be. Someday there will be Flash on the iOs. You can be sure of that (I mean Steve Jobs has an expiration date, right?)

, , , ,

19 Comments


Why Flash is not disappearing

All the debate about Apple vs Adobe really got me thinking lately. Last night , I woke up at 4 in the morning with the idea for this post. It suddenly hit me. Most of the latest trends on the web happened because it was allowed by Flash. If you think about 3D, Augmented Reality and ChatRoulette; all of those could not have happened if Flash didn’t exist and are currently not possible to implement using HTML5.

3D

3D really picked up when Papervision3D ported there library from ActionScript 2 to ActionScript 3. ActionScript 3 made it faster so you could actually do some interesting 3D without automatically killing the user’s CPU. Right after that we saw a wave of Flash website all using 3D in them. I’m not saying that was good; plenty of sites used the 3D for no reason at all except for the fact that it was cool. Now that the hype on 3D as dimmed down, we see better uses of the library. My point is that Flash opened up new possibilities. There are now a few more libraries for 3D (Away3D, Sandy3D, Five3D, etc) and I don’t think those would be possible with the current state of javascript. Right now everybody speaks about HTML5 and the Canvas but, boy, JavaScript is so not on par with ActionScript 3. jQuery makes it better but still. Here is a good example of a site that uses 3D.

3D models in Flash

Augmented Reality

AR was all the buzz last year and 3D is what really made it possible in the browser. AR is a concept that has been around since the 90s but it never picked up until it came to Flash because it made it accessible. For AR you mostly need 3D and a camera. The webcam is easily accessible in Flash and since Flash is so ubiquitous. Now video is possible with HTML5 but webcam won’t happen; maybe HTML6. So as AR evolve we will see tons of new applications coming our way.

GE augmented reality

ChatRoulette

Now ChatRoulette is really interesting. I don’t know if it is going to last or if it is going to disappear or change, but it definitely showed an interesting facet of the internet ( not talking about the impressing number of male exhibitionists out there). ChatRoulette could use the webcam and a media streaming server, but that is not what is happening here. Already all that is not possible in HTML5. What ChatRoulette is using is the new P2P service Stratus by Adobe integrated FlashPlayer 10. That is a new feature in the Flash player that most people are not aware of. What it does is that it connects users directly to send the video without going through the server ( in this case the ChatRoulette server) so it save a lot of money in bandwidth. Is this a cool feature? fuck yeah. Is this close to being included in HTML5? Not in years.

Chatroulette interface

The general conception is tying Flash to video, but that is not all that Flash does right. 3D, AR, and P2P are just some examples I took to illustrate the fact that Flash is pushing the web forward; I can easily think of many more: microphone access, Pixel Bender, ActionScript 3 (so much more fun to work with than JavaScript), AIR, etc. And that is just what is available right now in Flash Player 10. I can’t wait to see what will be available in the future.

, , , , , , , , , , ,

4 Comments


The iPad and me

I don’t really like to do opinion pieces. On the subject of technology, like religion, sometimes it doesn’t really matter what you say; both sides never really listen to each other. I don’t want to add another pointless my side is better than yours article. But I think it is sad when people say that such and such is bad and should die. Like it is currently the case with Flash and the whole iPad brouhaha. What I think these people don’t consider is the human impact behind this.

If Flash was to go away tomorrow, I’d find myself without a job. Well, I’d need time to learn another language and then I’d find another job but it wouldn’t be the same thing. I am really glad I found Flash and ActionScript 3. This is what I want to do for at least the next 5-10 years. What I like about it is that it speaks to both my programmer and creative side. It is also fast-paced; in the web agency world, you move from projects to projects really fast and you have to keep up with technology at the same time. It might seems weird but I really like that; no time to get bored. If it wasn’t for Flash, I don’t think think I would love my job as much as I do.

After the iPad announcement I found myself a bit confused and stressed about my future. The future of Flash seemed uncertain so my future seemed uncertain to. Not uncertain because of the evolution of technology (like HTML5) but because a company decided what the outcome should be. If all Apple products stop supporting Flash, this is not good news to me. What possibilities I had would lessen. Some would say that I shouldn’t tie myself to a technology, I know, and if I have too I will learn something knew, but as I said before I really like Flash. That made me think that it’s not only companies that can choose who gets to live or to fade (technology wise). Us, as developers, can put our weight in the balance too. As long as there will be people producing get content for the Flash platform, it will continue to thrive. If I like Flash that much, I must not be alone and from reading all those article that take Flash’s defense, I think I am right. So I feel more at ease now. The future is still uncertain but certainly less gloomy.

One last thing about the iPad. Zeldman in his post states that the computer of tomorrow is a computer that is dead simple but that in return doesn’t give all powers over it for the sake of usability, like the iPhone and the iPad do. I think that a portion of the population in fact wants that. Right now this portion might be big, but I think it will shrink because it doesn’t consider that the children that are raised right now have never seen the time when there was no computers. These will be way more computer literate than my parents lets say. For that I think a device like the iPad is closer to a toy than to a tool. If it wanted to dominate the netbook market, than it will fail. We don’t really know what is the role the netbook is going to take, but by making one that is limited in its usage, you also reduce your chance of getting it right.

Well that’s all I had to say.

, , ,

7 Comments


How to make Collada model double sided in Papervision3D

Well I searched for this for a little while and even tough it is pretty easy, if I didn’t figure it out at first probably other people had the same absence of mind. Also I find it hard to find example of Papervision3D and know which version was used; you find a lot of examples but you never know if the API changed since then so I am going to do a complete example with the version used.

The version used for this example is 2.1.92.

What I wanted to do was to load a Collada model in Flash an animate it. Every thing was going fine with the test models until I used the real models. You see the real models had holes in them that allowed you to see inside the model. Now if your material is single sided, when looking inside, you are going to see through the material and it will look buggy. The solution to this is just to make all material in your model (you can map multiple textures in one loaded Collada model), but that is not as easy as it sound. I tried a couple of options before hitting myself on the face. What did you learn back with ActionScript 2; wait till something is loaded before trying to modify it. This also applies to loaded models. Once loaded I made a little function that would cycle through all materials and make them double side.

Here is the code for the example :

//create all the actors of a Papervision3D scene
 
var viewport:Viewport3D = new Viewport3D(1000, 800);
addChild(viewport);
 
var renderer:BasicRenderEngine = new BasicRenderEngine();
var camera:Camera3D = new Camera3D();
var scene:Scene3D = new Scene3D();
 
//create the DAE/Collada object and load the model
 
var model:DAE = new DAE(false);
model.load("model.dae");
model.addEventListener(FileLoadEvent.LOAD_COMPLETE , daeLoadComplete, false, 0, true);
scene.addChild(model);
//finally add the enter frame listener to render the scene
 
addEventListener(Event.ENTER_FRAME, render, false, 0, true);
 
function render(event:Event):void{
  renderer.renderScene(scene, camera, viewport);
}
 
//this is where the magic happens, we cycle through all the materials of the model and make them double sided
 
function daeLoadComplete(event:FileLoadEvent):void{
  var matList:MaterialsList;
  var mat:MaterialObject3D;
  matList = model.materials;
  if ( matList ) {
    for each (mat in matList.materialsByName) {
      mat.doubleSided = true;
    }
  }
}

I didn’t include the import statement because I plainly forgot to send them to myself, but I will update this post to add them. Have fun loading models!

, , ,

6 Comments


How to connect to Google Analytics Data API in Flash

In one of my previous post, I explained how to connect to Google Analytics Data API in AIR. The problem with that way of connecting was that it only worked in AIR. In Flash it works locally, but as soon as you put in on your web server it stops working. Not it is cool to build an AIR (desktop) application that pulls data from Google Analytics, but it would also be cool to build a web application that does the same thing. Well I found out how to do just that. It is a bit more complicated because it involves a bit of server side coding, in this case PHP.

How the process works is that first you login to Google Analytics, Google will then send you a token that you must use when asking for data. So we will have two simple PHP files; one to login in and one to ask for data.

The first one looks like this:

<?php
//this file is called get_token.php
$user = $_REQUEST[user];
$pass = $_REQUEST[pass]
 
require_once 'curl.php';
$curl = new Curl;
$response = $curl-&gt;post('https://www.google.com/accounts/ClientLogin', array(accountType => "GOOGLE",  Email =>$user, Passwd => $pass, service => "analytics", source => "zedia-GAStats-0" ));
$tempArray = explode("Auth=", $response);
?>
<root>
	<token><?php echo ($tempArray[1] ); ?></token>
</root>

The second one looks like this:

<?php
//this file is called call_ga.php
require_once 'curl.php';
$url = $_REQUEST["url"];
$token = $_REQUEST["token"];
 
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl2, CURLOPT_HEADER, "0");
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl2, CURLOPT_URL, $url);
 
curl_setopt($curl2, CURLOPT_HTTPHEADER, array('Authorization: GoogleLogin auth=' . $token));
$response2 = curl_exec($curl2);
echo ($response2);
?>

As you can see to make my calls to Google I am using the cURL library that is usually already installed on your server if you have PHP. Also for the get_token.php I am also using the Curl class, made by Sean Huber, that just makes it easier to work with cURL.  Upload these files to your server. Now that we have the server side figured out, we can move on to the Flash part;  here it is:

package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.text.TextField;
 
public class Main extends Sprite
{
  private var loader:URLLoader;
  private var _loader2:URLLoader;
  private var _textField:TextField;
  private var _token:String;
  private var _buffer:String = "";
  public function Main():void
  {
    loader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, _onTokenLoaded, false, 0, true);
   //this call will load the token
 
    loader.load(new URLRequest("http://www.YOUR_URL_WHERE_THE_PHP_RESIDE.net/get_token.php?user=YOUR_USERNAME&pass=YOUR_PASSWORD"));
 
    _textField = new TextField();
    _textField.height = 300;
    _textField.width = 300;
    _textField.multiline = true;
    _textField.wordWrap = true;
 
    addChild(_textField);
  }
 
  private function _onTokenLoaded(event:Event):void {
    var tempString:String = String(loader.data);
    tempString = tempString.substring(1, tempString.length);
    var tempXML:XML = XML(tempString);
    _token = tempXML.token;
 
    _textField.text = _token;
 
    _loader2 = new URLLoader();
    _loader2.addEventListener(Event.COMPLETE, _onFeedLoaded, false, 0, true);
 
    var request:URLRequest = new URLRequest("http://www.YOUR_URL_WHERE_THE_PHP_RESIDE.net/call_ga.php");
    var urlVar:URLVariables = new URLVariables();
    urlVar.token = _token;
    urlVar.url = "https://www.google.com/analytics/feeds/accounts/default";
    request.data = urlVar;
 
    _loader2.load(request);
  }
 
  private function _onFeedLoaded(event:Event):void {
    _textField.text = String (_loader2.data);
  }
 }
}

What you basically do is that you use your server to do all the communication between the Flash and Google. Everytime you will want a different feed to get different data you will call the call_ga.php file. It is that simple. If you have any question on this feel free to ask them in the comments.

, , , , , ,

12 Comments


An update on Flash SEO

I was just in Jim Corbett Flash Player Internal v2 presentation at FITC and I learned a couple new facts about SEO that I wanted to share.

First, it now seems that Google will be indexing loaded files; that was intented for a while and I will still have to make some experiments to see if it really works but Adobe says it works. Well it doesn’t really work like they would want it to work: when Google sees that the SWF is loading a file, it doesn’t load it in the currently playing Flash file but it makes a note of it and will load and reference that content later. The text in there will still be associated with the previous url, but it won’t play in the right context. That last caveat doesn’t bother me much; my biggest concern was that all the work I do is preloaded by an external preloader, so none of my content was Flash SEO friendly. Now it will get indexed.

Another interesting fact that was kinda hinted in the presentation was that the SEO Flash player is not suppose to index text when it is out of bound of the stage; when the user doesn’t see it. But, if you put a button outside of the viewable area and that button will bring the SWF in a state where text is displaying on the stage(viewable), that text will be indexed. The problem is that the headless player doesn’t check if the button is viewable or not. This is not confirmed and I will also have to make tests on this.

Well I have to get back in there now.

,

3 Comments