| Subcribe via RSS

MovieClip Exploder class

January 18th, 2012 | No Comments | Posted in Adobe Air, adobe flash, flash

I built a logo particle explosion class for a client. Unfortunately they decided not to take this route. It came out rather cool so I thought I’d share this with all of you. You can download the source code and use it anywhere you like. It would be cool if you would tell me where you used it tho.

Download MovieClipExploder source code

Usage:

1. Download the zip file
2. Copy the ‘com’ folder in there to your project directory
3. Make a ‘particle’ sprite/MovieCilp in your .fla file and  choose ‘Export for Actionscript’ when you make it as a MovieClip. Type: ‘particle’ in the ‘Class’ field. (you can use custom shapes if you want to).

Settings for Particle movie clip in flash

3. Particle creation Settings

4. Make the shape inside the particle movie clip as another movie clip and call it “gr”. No actionscript export necessary here. But you can now add effects to this asset. I added a little blur in the example.
5. Make sure your logo has an instance name and it’s on the stage. Then add the code:

import com.teemusk.ExplodeMovieClip;
var logoexploder:ExplodeMovieClip = new ExplodeMovieClip(logo);
addChild(logoexploder);
logoexploder.startEmitter();

6. Publish your movie and watch those particles fly.

That’s it. Enjoy!

Tags: , , , , , , , , , , , , , , , , ,

Passing variables to a function

January 11th, 2012 | No Comments | Posted in adobe flash, flash, Objective-C

My lingo is so Actionscript, but that is changing slowly. Variables are methods, and we’re actually passing properties in Objective-C. But ok. Yesterday I wrote about declaring and calling functions/methods in Objective-C. Now I’ll try to explain how to declare functions that accept variables and how to pass variables to them. Also I cover briefly how to get ‘trace’ statements in Objective C.

So let’s cut to the chase.

Trace Statements

Actionscript:

var string:String = "I AM STRING";
trace("I am getting traced in the console ");
trace("I am a variable: "+string);

Objective-C

NSString *string = @"I AM STRING";
NSLog(@"I am getting traced in the console");
NSLog(@"I am a variable %@",string);

Now note how variables work in NSLog statements. characters starting with % sign will get substituted by comma separated variables. Also all string defined have to have “@” in front of them.
They’re a bit to get used to. I will pass a cheatsheet of different variables

Actionscript

private function myFunction(foo:String){
trace("I got the variable "+foo);
}

 Passing a variable to a function

Passing a var to a function in Actionscript:

private firstFunction():void{
var str:String = "This is passed data";
anotherFunction(str);
}
private anotherFunction(s:String):void{
trace(s); //Output: This is passed data
}

Passing a variable to a function with Objective-C:


//First add this line to your header (.h) file;
- (void)anotherFunction:(NSString *)s;

//then in Class file (.m) you can call this function like so:
-(void)firstFunction{
NSString *str = @"This is passed data";
[self anotherFunction:str];
}
- (void)anotherFunction:(NSString *)s{
NSLog(@"%@",s); //Output This is passed data
}

Make sure ‘firstFunction’ is called. Try to use AppDelegate’s initWithOptions as your firstFunction.

Objective C NSLog cheatsheet:

%@     Object
%d, %i signed int
%u     unsigned int
%f     float/double
%x, %X hexadecimal int
%o     octal int
%zu    size_t
%p     pointer
%e     float/double (in scientific notation)
%g     float/double (as %f or %e, depending on value)
%s     C string (bytes)
%S     C string (unichar)
%.*s   Pascal string (requires two arguments, pass pstr[0] as the first, pstr+1 as the second)

%c     character
%C     unichar

%lld   long long
%llu   unsigned long long
%Lf    long double
Tags: , , , , ,

Objective-C Here I come

January 10th, 2012 | No Comments | Posted in adobe flash, Apple, flash, Objective-C

Okay. I’ve been learning Objective-C on and off for quite a while now. I’ve been doing it mostly using The Big Nerd Ranch books.

I can tell you it has not been easy. While all tutorials in these books are quite straightforward and work out just great when you follow a book, they still haven’t helped me to get my head around this language. I get the syntax, I get how the structure should work, but some of the concepts are so different coming from ECMA script language background such as Actionscript or Javascript. Painful.

Also I have googled around a lot. While there are some blogs that describe a bit about migrating from ECMA script to C based language, they haven’t helped me out too much.

Therefore I will try to add my 5 cents to the blogosphere about this subject. (And don’t judge me if I’m wrong in my theories presented here. I’m just a n00b.).

Declaring and calling a function

This is probably the first thing you want to do. In Actionscript 3 I would do this:

Defining a function:

private myFunction():void{
//Do something;
}

To call this function from another function I would just:

private anotherFunction():void{
myFunction();
}

In Objective C it’s not as straightforward. Defining a function like this won’t allow to call it from another function.

Defining a function:

First add the function description to an interface (yeah that’s the myClass.h file. Objective C calls them Headers).

- (void)myFunction;

Then in the class itself (myClass.m file) define this function completely:

-(void)myFunction{
//Do something
}

And then you can call it from another function:

-(void)anotherFunction{
[self myFunction];
}

 

I hope you get the idea how it works. I will try to add more examples soon.

Tags: , , , , , , ,

Writing to applicationDirectory with Adobe Air

October 27th, 2011 | 2 Comments | Posted in Adobe Air, flash

I had a lot of painful trouble with flash.filesystem.File functionality the other day. The problem is that File.applicationDirectory is read-only. I understand that it’s read only as on a mac we’re inside the <myair>.app/Contents… folder when we’re executing scripts and it is not very wise to write stuff in there.

Most of the times the File.desktopDirectory or File.documentsDirectory will meet our needs just fine and we can write stuff there. That was not the case for me. I needed an air desktop app which would work like a website or projector with loading data next to itself (from ‘images’ or ‘data’ folder etc.). Also I really needed to write a log out of the app so I can see how people are using it and if it’s app’s problem when it crashed.

Long story short. Here is my solution which is a bit of a hack but not too bad and at least it works ‘unlocking’ the File.applicationDirectory so we can have read/write access to it.

The trick is to resolve path for the applicationDirectory first and according to it’s native path we resolve the folder as File.userDirectory. My code goes like this:


var appPath:File = File.applicationDirectory.resolvePath("");
var fromUserPath:File = File.userDirectory.resolvePath(appPath.nativePath);

fromUserPath will take us to the exact same place as appPath, but with a difference that it is read/write and also you can do fromUserPath.parent.parent.parent to it to get to the folder next to the air app on a mac.

So my code that handles the starting path for my app on win and mac (and debug mode) goes as follows:

if (Capabilities.os.toLowerCase().indexOf("win") > -1){
localPath = File.applicationDirectory.resolvePath("");
}else if (Capabilities.os.toLowerCase().indexOf("mac") > -1){
var appPath:File = File.applicationDirectory.resolvePath("");
var fromUser:File = File.userDirectory.resolvePath(appPath.nativePath);
localPath = fromUser.parent.parent.parent;
}
if(Capabilities.playerType == "Desktop" && Capabilities.isDebugger){
localPath = File.applicationDirectory.resolvePath("");
}

//if you trace localPath.nativePath now you can see that you’re on a directory that your air app is at.

I had a terrible headache with this and could not find a straight answer by googling so I thought I’d give something back to community. Enjoy.

Tags: , , , , , , , , ,

Chrome vs. Safari

April 16th, 2010 | 11 Comments | Posted in surfing the web



I’ve been working on a mac for the last 10 years. So I guess using Safari as the main browser seems like an obvious choice.

I work as an Adobe Flash developer so having different browsers installed is pretty much a prerequisite. So far Safari has always been above all other ones.

So far I haven’t even thought of switching my default browser, until recently when I discovered that Google Chrome is out for Mac as well (old news… yeah, I know). First test showed that it’s an awesome and fast browser and a very strong competitor to Safari. So strong in fact that I changed it to my default browser about a month ago.

But now, a month later I’m changing my defaults back to Safari. And let me tell you why.

1. Safari Activity Window. This is invaluable tool for Flash Developer. I can’t live without it and after a month of searching I haven’t found a good equivalent plugin for Chrome.

2. Home page that shows all your most important sites in Safari. There is SpeedDial plugin for Chrome, but it just does not feel (nor look) the same.

3. Flash rendering. Somehow Chrome is just not good enough rendering flash sites. For instance YouTube controls are not clickable with Chrome. Only thing I can do in YouTube with chrome is to click on the video window to make it pause/play and that’s it. Sucks!? Yeah, I know.

Although searching straight using address bar is a great feature on Chrome. And rendering and using Google Docs (scrolling with MacbookPro touch pad) works great. Still I must say I tried. It wasn’t so bad, but I must admit Safari is still the best browser for my needs.

Please share your experience with those two browsers in the comments below.

Thanks!

Tags: , , , , , ,

Good folder structure for a Flash project

April 13th, 2010 | 1 Comment | Posted in adobe flash
Every developer has his own setup when they work, their own class system and their own folder structure. For some the latter is chaotic with all the files in one folder, for others it’s nice and tidy.

I personally believe that a good folder structure can save time and create less stress. So let me tell you, how I like to keep my project organized.

Project Root Folder

The project root folder Holds three folders: assets, source and deploy.

Assets Folder

Assets folder is the messiest among those three. In it are all the files I get from the client, the designer or other stakeholders. Quite often I try to make subfolders with dates inside the assests folder so I will always know which is the latest stuff.

Source Folder

Source folder has all the source .fla’s and a com folder. Com folder has all the classes.
IMPORTANT! Fla files will then all publish to ../deploy/ folder which I set in flash from File>Publish Settings…

Deploy Folder

Deploy folder has all the deployment stuff. Usually it has folders like xml, images, videos etc. And it also has all the html and swf files.
Now it’s really easy to manage stuff.
If you need to deploy a build to a server you just upload the contents of deploy folder. If the client needs the source code you zip up the source folder and upload the zip.
The most common mistake is to have your fla’s and swf’s in the same folder. Sometimes developers even have their assets there which makes it quite impossible to quickly upload stuff.
So just a suggestion. Try to keep your stuff organized from the get-go and you will save a lot of braincells which die when you are pissed off at something.
Tags: , , , , , , ,
  • Latest Tweets