Friday, June 20, 2008

Feature request

I've added a feature request to fix SEO in the flash player, please vote if you feel it's a good idea.
http://bugs.adobe.com/jira/browse/FP-362

Monday, June 09, 2008

Hi,
Found this in a new JavaScript book (Douglas Crockford's 'JavaScript the Good Parts' [O'Reilly]) converted it to AS3 and wanted to
share, this little object blows my mind, read it over and I'll
explain below.


var myObject:Object = function() : Object {
var value = 0;
return {
increment: function (inc:Number = 1) {
value += inc;
},
getValue: function() {
return value;
}
}
}();

myObject.increment();
trace(myObject.getValue()); // traces: 1
myObject.increment();
trace(myObject.getValue()); // traces: 2


There's a few odd things here, we are able to persist the value of a
variable from inside of an object and run calculations on it. This is
the same thing as creating a class and then defining a class level
variable inside of it. We are then defining functions inside of this
returned object that can use these persistent variables.

Other odd things, notice the last line of the myObject definition. We
are executing the function right away, personally I never seen this
before but opens my mind a little further into the way that objects
interact and what calling a function really means.

This all runs in AS3 but if you go into this to deeply I personally
wouldn't want to step in and work on that code. I think this is more
interesting to show how objects can interact and what is happening
and how things can be passed around.

Thanks to J-C for sending this over to me. If you don't fully
understand it's cool but we should cover some of this at a fcny meeting
some day. There are other ideas in that book that will blow your mind even further
but I'll spare you for now, this one just has stuck in my mind and I
wanted to share.

-Tyler
Zemanta Pixie

Labels: , ,

Wednesday, April 23, 2008

Flash Coders NY MVC

I've been doing ActionScript sessions at the flash coders meetings and have come up with a simple MVC framework that is much easier to understand and explain then the standard things that you see out there. If you are looking for something to start with it isn't bad.
Download the files here!

Labels: , ,

Tuesday, April 22, 2008

Runtime expression evaluation in ActionScript

The Tamarin port that I mentioned before is big and heavy and classes upon classes porting everything that they could from the Java source that really creates the swf byte code. The other way to go about making eval() is to break the problem down to what really needs to happen and not cloud your code with Java garbage. Amazing what you can do with ActionScript. This is a really amazing piece of code, really well written in my opinion, Check it out here.

I hope more is added to the library and a few things are changed a little but I'm really excited how small it is. I will try and add it into Wrapper when I get a chance.

Labels: , ,

ActionScript 101 and simple MVC

I'm speaking again at the FlashCodersNY meeting wednesday night. I'm going to continue my talk from a few weeks ago about class structure. Last week I should how to make a simple MVC project structure if you missed it here are the files.

Labels: , , , ,

Saturday, April 12, 2008

New ActionScript Stuff

Adobe Photoshop ElementsActionScript is the coolest but to prove the point here is a few things that I've come across my travels lately.

New Photoshop Elements made in Flex
Adobe is starting to take clue web 2.0 area of getting away from the desktop and doing a pretty good job of understanding the market. Other efforts like Adobe Connect isn't really mind blowing if you ask me but this is a pretty nice application that I can see a lot of people using. It is a little to simple for me but I also am not really the target audience so I still think it is pretty great. It is nice that Adobe is using there own products to create but it also scares me a little. I don't want them taking the thunder away from other businesses that are creating comparable products with there technology already. There are a few of products that already have this type of functionality but it is Adobe's niche also so I understand but hope that it doesn't continue to much. Buzzword was questionable but they are adding some nice text features that I imagine were inspired by this purchase.

An ActionScript Compiler written in ActionScript
This is an amazing project that I think was missed buy the ActionScript community at large. The ability to compile within ActionScript opens the doors to all kinds of dynamic functionality that is currently very limited. I use methods like getDefinition all the time trying to create some form of flexibility within my projects but eval()eval()() has been greatly missed and I look forward to maybe one day coming back to ActionScript. I haven't spent a lot of time with this project but I'd like to see what it is capable of with out crashing everything.

ActionScript ActiveRecord for AIR SQLite
I'm working on a big AIR app and have already written all my database stuff but next time totally using this. It also comes with some really nice utilities that would be great to

JQuery in ActionScript: as3Query
This is really awesome but the thing that really pulls me back is it's still written in compiled ActionScript, it would be really nice if something like this could be rendered from a dynamically. This opens my mind to a few things for Wrapper but not really with this implementation.

Physaxe: Haxe Physics Engine
Pretty nice, it visually seems faster then anything else I have seen but testing would have to be done to prove that. But pretty impressive for realtime flash stuff.


I also have to add, I've been working in Flex a lot and I don't agree with the component architecture or the size of the framework. My biggest gripe is that it promotes the creation of projects that have more code than is comprehensible and requires a developer to trust the structure to much. To many things are automatically done for you without very much control for overriding or restructuring. It's all or nothing and the whole thing is big and slow. But also take into account that I still use it because there are some nice things about it too.

Labels: , , , , , , ,

Wednesday, January 02, 2008

Tyler Larson's Quick Start Guide

Wrapper is a new technology that overlays your HTML web page, enabling your content to render consistently in all browsers, while adding the features of the Flash Player (think anything that can be done with Flash, Flex, and ActionScript) to any part of your HTML and CSS.

How is this possible? We've created an HTML/CSS browser that runs in the Flash Player. After your standard HTML page has loaded, the contents are taken over and rendered within Wrapper --this is the key to cross-browser consistency. Even more exciting is what can be done in Wrapper to enhance your page.

Wrapper is based on standard XHTML and CSS, but you can also add logic to your Wrapper page with scripts, by calling JavaScript Object Notation (JSON) methods, and using runtime-loaded plugins written in ActionScript 3. Most of Wrapper's features are tied directly to how HTML and CSS render in every modern browser but now you can add some exciting, enhanced features such as: filters, custom fonts, blend modes, custom shapes, gradient fills --and so much more.

So how do I get started?
Just open any text editor and make something like this.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8" />
<title>main</title>
<link rel="stylesheet" href="main.css" type="text/css" />
<script type="text/javascript" src="http://0in1.com/wrapper.js"></script>
</head>
<body id="wrapper" onload="wrapper('http://0in1.com');">
<div id="box">
<p>Hello World!</p>
</div>
</body>
</html>

and save this document as index.html

Then make a new document called main.css and make something like this inside:

/* hide from ie on mac \*/
html { height: 100%; }
/* end hide */
body {
margin: 0; padding: 0; height: 100%;
background-color: #0099FF;
}
#box {
left: center;
width: 600px;
height: 50%;
background-color: #FF9900;
shape: json('{ "type":"rounded", "w":10 }');
}
p {
font-file: url("http://0in1.com/assets/fonts/MankSans.swf");
font-family: "MankSans";
color: #FFFFFF;
font-size: 100;
}

Save this and put both files into a folder on any web server (including localhost).
At this point we have to make a crossdomain.xml file which will allow Wrapper to read the content on you page, If you use the downloaded version of Wrapper you wont need this. To make this go back to your text editor and create a new file named crossdomain.xml and place this inside.

<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="0in1.com" />
</cross-domain-policy>

All done, just navigate to that location on your server and you should see what you've made. If everything worked you should see "Hello World" inside of a orange box with rounded corners inside a blue box. It's a simple example, but you can see how easy it is to use custom shapes and fonts. Adding more complex interaction or creating an AJAX style application is not much more difficult.

Saturday, October 27, 2007

How to call a class that you haven't imported.

There was a post on the FlashCodersNY mailing list that was asking about how to access code that you dont have scope to. There are a few ways to do this but in general if you are having this problem it might be a sign that you application is not build the way that it should be. Unless you are doing something dynamic I suggest passing scope or importing an actual reference.

Step 1,
Import your class and make a reference to it. The import statement itself will not compile your class into your swf. If you never reference it, the compiler will simply take it out to make your swf smaller.

package {
import com.project.Class1; // your import
public class Main {
private var class1:Class1; // the reference
}
}

Step 2,
In a different class you can then get access to Class1 by using getDefinition();
var class1:Class = ApplicationDomain.currentDomain.getDefinition( "com.project.Class1" ) as Class;   

Here is a full example, source code can also be downloaded here.
// Document class
package {
import flash.display.Sprite;
import com.project.Class1; // we will import this here
import com.project.Class2;
public class Main extends Sprite {
private var class1:Class1; // And then give reference to it so that this class is compiled into the swf
public function Main() {
var class2:Class2 = new Class2();
}
}
}

// class that is not included in
package com.project {
public class Class1 {
public function Class1() {
trace("class1");
}
}
}

package com.project {
import flash.system.ApplicationDomain;
public class Class2 {
public function Class2() {
var class1:Class = convertStringToClass("com.project.Class1");
new class1();
trace("class2");
}
public function convertStringToClass( className:String ) : Class {
return ApplicationDomain.currentDomain.getDefinition( className ) as Class;
}
}
}


You dont need to use ApplicationDomain to make this work but you can learn more why you might need this from the links below.

I've also added links to other similar actionScript 3 methods with similar function.

About ApplicationDomain
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/ApplicationDomain.html#getDefinition()
and a little more
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000327.html

and other package.utils functions
http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html

getDefinition()
Gets a public definition from the specified application domain. The definition can be that of a class, a namespace, or a function.

describeType()
Produces an XML object that describes the ActionScript object named as the parameter of the method. This method implements the programming concept of reflection for the ActionScript language.

getDefinitionByName()
Returns a reference to the class object of the class specified by the name parameter.

getQualifiedClassName()
Returns the fully qualified class name of an object.

getQualifiedSuperclassNam()
Returns the fully qualified class name of the base class of the object specified by the value parameter.

How to call a class that you haven't imported.

There was a post on the FlashCodersNY mailing list that was asking about how to access code that you dont have scope to. There are a few ways to do this but in general if you are having this problem it might be a sign that you application is not build the way that it should be. Unless you are doing something dynamic I suggest passing scope or importing an actual reference.

Step 1,
Import your class and make a reference to it. The import statement itself will not compile your class into your swf. If you never reference it, the compiler will simply take it out to make your swf smaller.

package {
import com.project.Class1; // your import
public class Main {
private var class1:Class1; // the reference
}
}

Step 2,
In a different class you can then get access to Class1 by using getDefinition();
var class1:Class = ApplicationDomain.currentDomain.getDefinition( "com.project.Class1" ) as Class;   

Here is a full example, source code can also be downloaded here.
// Document class
package {
import flash.display.Sprite;
import com.project.Class1; // we will import this here
import com.project.Class2;
public class Main extends Sprite {
private var class1:Class1; // And then give reference to it so that this class is compiled into the swf
public function Main() {
var class2:Class2 = new Class2();
}
}
}

// class that is not included in
package com.project {
public class Class1 {
public function Class1() {
trace("class1");
}
}
}

package com.project {
import flash.system.ApplicationDomain;
public class Class2 {
public function Class2() {
var class1:Class = convertStringToClass("com.project.Class1");
new class1();
trace("class2");
}
public function convertStringToClass( className:String ) : Class {
return ApplicationDomain.currentDomain.getDefinition( className ) as Class;
}
}
}


You dont need to use ApplicationDomain to make this work but you can learn more why you might need this from the links below.

I've also added links to other similar actionScript 3 methods with similar function.

About ApplicationDomain
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/ApplicationDomain.html#getDefinition()
and a little more
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000327.html

and other package.utils functions
http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html

getDefinition()
Gets a public definition from the specified application domain. The definition can be that of a class, a namespace, or a function.

describeType()
Produces an XML object that describes the ActionScript object named as the parameter of the method. This method implements the programming concept of reflection for the ActionScript language.

getDefinitionByName()
Returns a reference to the class object of the class specified by the name parameter.

getQualifiedClassName()
Returns the fully qualified class name of an object.

getQualifiedSuperclassNam()
Returns the fully qualified class name of the base class of the object specified by the value parameter.