Matt Kenefick
Contact Me Experiments Blog Portfolio

Archive for the ‘Actionscript 3.0’ Category

What makes up an Android App ?

Sunday, February 8th, 2009

This is taken from the Google documentation but I’m going to attempt to explain it in common developer terms and relationships. Since they are specific, some examples will not be DIRECTLY related, but the idea will help you understand what it’s about a little.

Apps are typically built on a combination of 4 building blocks:
- Activity
- Broadcast Intent Receiver
- Service
- Content Provider

So I’ll jump into the first one which is Activity. This is basically each individual screen of your application. So if we were talking about a webpage… Your homepage is an Activity, your login page is an Activity, your success/error page is an Activity… Basically every screen is an Activity. Of course each screen, just like on a webpage, is built from different components. In the web world, these would be like DIV tags, INPUT components, IMAGES, etc… The page as a whole is an Activity.

Broadcast Intent Receivers (BIR) are similar to, but not identical to, events in Actionscript. In the Android world, a BIR would handle external events of the phone. So if the phone starts ringing, the time changes to midnight, or your lose service.. Your app receives an Event to the BIR. You can think of this as being similar to the Actionscript EventDispatcher. Like the EventDispatcher, you can also broadcast events instead of just listening for them. Some Android code examples would look like… “Context.registerReceiver();” or “Context.sendBroadcast();” .. Looks an awful lot like “addEventListener” and “dispatchEvent” doesn’t it?

A Service is something that will play in the background. The best example (and take THIS iPhone) is playing music. Attaching sound to an Service will allow you to listen to your song as you’re going through different screens in your app. Attaching sound to an Activity will cause your song to stop playing when you switch screens. Services are totally code based, obviously. Try to relate it to the services on your computer. You have services running all the time that manage your network connections, LAMP servers, audio controllers, etc. You don’t SEE them, but they’re handling code continuously in the background. You have control over these as well. You can communicate to see what song is playing, change the song, etc.

The Content Provider is a place to store data. SQLLite or other. It lets you share data with other apps on the phone. There is no specific directory, like “Uploads” or “Files” that every app can access. It must be passed through the Content Provider. This will be covered more later, but for now.. Just think of it as a database that you store/retreive information. Content Provider examples: Contacts, Media, Images, Groups, etc…

These will be covered more later, but hopefully gives a more ‘real-world’ approach to what these terms actually mean.

Actionscript to Android

Sunday, February 8th, 2009

Over the next few weeks.. I’m going to write out some very simple to progressively more advanced Actionscript to Android comparisons. Since it’s all Java based, it should be fairly simple to see the differences and merge your way from AS3 to Android. Instead of explaining a bunch of stuff, I’ll just jump directly into it.

Actionscript 3.0

package com.android.hello {
 
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
 
  public class HelloAndroid extends Activity{
    /** Called when activity is first created */
    public override onCreate( savedInstanceState:Bundle ):void {
      super.onCreate( savedInstanceState );
 
      var tv:TextView = new TextView( this );
      tv.setText("Hello, Android");
      setContentView( tv );
    }
  }
}
Android (Java)

package com.android.hello;
 
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
 
  public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate( Bundle savedInstanceState ) {
       super.onCreate( savedInstanceState );
 
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
    }
}

This is a very simple example that helps show the differences in syntax.

Actionscript 3 Android (Java)
- Enclose package in brackets
- Override after “public”
- Return type (void) AFTER parameters
- Variable type “var varname:Type”
- Do not enclose package
- Override set before method
- Return type (void) BEFORE method name
- Variable type “Type varname”

Fractal4D: First Release

Wednesday, November 26th, 2008

Check out this temporary page for Fractal4D updates!

—————————–

Here is the first public release of Fractal4D. It is still beta, but there is a built-in auto updater that will make sure you have all the necessary updates without having to check for announcements. The auto-updater does not affect any files or directories outside of its own application directory. This is an AIR app, so you will need Adobe AIR to use it. Please leave feedback, comments, and suggestions.

OR


Download F4D


Donate to help make Fractal4D better!

Notes:

  • It defaults to exporting an illustrator script. If you want to save an image, you must uncheck “Export to Illustrator” in the Options menu.
  • Version 1.22 is going through changes with easing methods. The only one that exports exactly for illustrator is linear. The others are undergoing changes. Sorry.
  • Better documentation and cleaner menus are coming!

If you find any bugs let me know. I am going to fix the ones that exist and you will all be updated automatically when this happens. I wanted to get this out before Thanksgiving and there is substantial to play with and get familiar with before these bugs will affect you. I will also be adding an additional hotkey to simulate a mouse click to start/stop your lines.

More to come! View the other posts to see some demo videos.

Videos:
Exporting Illustrator - http://mattkenefick.com/blog/2008/11/f4d-export-to-illustrator/
General Options - http://mattkenefick.com/blog/2008/11/f4d-general-options-demo/
Color Shifting - http://mattkenefick.com/blog/2008/11/f4d-color-shifting-demo/

Examples:

AIR: Creating an AS3 updater

Tuesday, November 18th, 2008

Here is a simple code that will check a server to see if there are updates to your app. It reads an XML file that contains details like: Version, Name, Release, Changes, Download Link. You can add/remove as you wish. It compares to a set version variable in the kapp class. If it does not match, it shoots out an event that you can monitor.

This is a very simple example. Later I will post an example of:

  • Check server for updates
  • If version is greater, ask to update
  • If yes, download update automatically.
  • Automatically show new app without restarting.

This will let the user very easily update your AIR apps without having to open any AIR files or doing anything manually. You simply say “Update”, and from there.. it downloads, installs, and reopens automatically.

Keep an eye out.

Download Source

AIR: Dynamically compiling a SWF file

Tuesday, November 18th, 2008

Here’s something I was faced with and conquered:

I was compiling my AIR application and did not want a SWF file to be left in the directory. You could decompile it, you could try to open it on its own, and it just looked unprofessional. So in order to resolve this I thought, “Well I can just rename it to something else.” But that was not quite the effect I wanted.

What I ended up doing was dividing it up into multiple files, scrambling the data inside, encrypting each file, and spreading them out. This makes it so that no one can actually just throw your SWF into a decompiler and looks a little more legitimate.

The reason this can be done is because of ByteArray, File, Loader, and LoaderContext. What you do is:

  • Create a ByteArray
  • One-by-one write each file’s data to the ByteArray in the correct order
  • Use: loaderContext.allowLoadBytesCodeExecution
  • Create a Loader and load the Bytes in ByteArray:  loader.loadBytes( your_byte_array, loaderContext );

“allowLoadBytesCodeExecution” will actually let you load a file from its internals rather than creating an archive on the system first. If there is no archive, there is nothing to decompile.

With this method, you can split your file into multiple sections, encrypt the code in different ways, and more. Some possible uses:

  • Encrypt files using a personal salt (password) so it is password protected
  • Encrypt files using MAC address so it only works on a specified computer

I have it working well and all, but there is still more to experiment with. I just thought I would share the good news!

F4D: Export to Illustrator

Sunday, November 16th, 2008

I was a little tired when recording this one.

F4D: General Options Demo

Sunday, November 16th, 2008

F4D: Color Shifting Demo

Sunday, November 16th, 2008

“Great” developers versus great developers

Thursday, November 13th, 2008

There are a lot of really good developers out there. I feel some of them climb the ladder and either hit the “great” category, or the great category. I use one in quotes to represent the same area of expertise but with a slight difference that means a lot. I will relate this area to design patterns for this example.

A “great” developer knows the ins-and-outs of OOP, knows design patterns, knows how to implement them properly, and follows the rules of the pattern strictly.

A great developer knows the ins-and-outs of OOP, knows design patterns, knows how to implement them properly, and follows the rules of the pattern loosely.

Design patterns are not laws. There are things you can do in your coding that will go against the the pattern definition, but leave the heart and idea in tact. I have seen some pieces of code get criticized because they are not a “proper singleton” pattern or … whatever the excuse is. The truth is that the “great” developers are either not good enough to actually bend the rules or they have nothing else going for them except perfection in patterns.

Patterns are great because they are a universal concept to an approach and they have been proven to organize code, but these are not restrictions as some people seem to think we are bound to. It is okay to bend concepts of a pattern if it fits your application more or makes more sense. I have seen situations where actually implementing the pattern to perfection is more confusing then taking a small detour. Knowing when to use a proper pattern and when to bend the rules a little is what separates a “great” developer from a truly great developer. When you are a young programmer, you are afraid to stray far from what you know so you do it strict and to the point. As you gain more experience, you realize that being so strict was never necessary. That concept applies further and further.

( When I say “bend” the rules, I do not mean tearing them to shreds and doing your totally own thing and claiming to be something else. )

Design patterns, and most concepts in developing, are not rules… They are more like guidelines.

AS3 KMenu: Source coming later tonight…

Tuesday, November 11th, 2008

Check out this page for the demo: http://mattkenefick.com/x/kmenu/readme.html

Downoad Source! ( You should read the page above first though )