Archive

Archive for the ‘Uncategorized’ Category

AIR3 :: FREObject and using accessors on AS3 class

October 7th, 2011 Michael Schmalle 4 comments

Hi,

UPDATE: Seeing as I have applied for the FlashBuilder 4.6 preview and not heard back yet, I am flying by the seat of my pants. I think I got this issue solved(not passing null for the FREObject.newObject() call), it must have been an exception getting swallowed somewhere because I have pushed ahead farther and backtracked to this problem. Things work, I hate sounding like an idiot below but hey this is bleeding edge development.

The Problem Solved:Now that I think about it, the call to FREObject.newObject() created a String and then the actual Exception came from the code trying to set “test” on the String class which we know does not exists.

I think this method signature might bite a couple devs in the ass once or twice. :)

I have been scowering the scant documentation on the FREObject class and most of it is copy and paste everywhere. I’m at about 4 hours of serious determination when I am slowly realizing either I am doing something wrong or using an ActionScript class’s accessors just don’t work in the just released Java API for AIR native extensions.

I can successfully set a public var, call a method but when I try to set a setter property, I get an com.adobe.fre.FRENoSuchNameException.

AS3 class:

package com.teotigraphix.android.foo {
public class Bar {
    public var baz:int;
    private var _test:String;
    public function get test():String{
         return _test;
    }
    public function set test(value:String):void {
         _test = value;
    }
    public function Bar() {
    }
}
}

Works:

FREObject instance = FREObject.newObject("com.teotigraphix.android.foo.Bar");
instance.setProperty("baz", FREObject.newObject(42));

Doesn’t work:

Throws com.adobe.fre.FRENoSuchNameException.

FREObject instance = FREObject.newObject("com.teotigraphix.android.foo.Bar",);
instance.setProperty("test", FREObject.newObject("42"));

Does anybody out there have an idea or have seen this before? Maybe a bug?

Mike

FlashBuilder 4.5 :: Getting FlexUnit to work with Mobile components

October 3rd, 2011 Michael Schmalle 5 comments

Hi,

Maybe I missed this in the plethora of documentation of FlashBuilder 4.5, maybe it’s coming in the next free update but when I tried to run FlexUnit in the Flex Mobile Project, the IDE said FlexUnit is not supported in this version.

Well, I need to test mobile user interface components for my next product set, how do I get this to work? Going back to a previous problem I had with Flex Library projects rejecting the existence of the mobile skins theme I realized this must be the same problem in a way.

Side Note:

If you want to create a Flex Library project using Mobile skins say creating component skin that subclass MobileSkn, you need to add the theme SWC to the build path.

  1. Right Click on the library project.
  2. Select Properties
  3. Select Library Build Path
  4. Select the Library path tab
  5. Click Add SWC…
  6. Browse to the folder approximately in C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.1\frameworks\themes\Mobile\mobile.swc
  7. Select the newly added swc in the Build path libraries:
  8. Expand the selection
  9. Double click on the Link Type:
  10. Select External from the Link Type: dropdown
  11. Click OK
  12. Click OK

Now your Library project is a Flex Mobile Library project. I am sure they will have this fixed in the next update.

Getting back to FlexUnit

What I ended up doing was adding the two mobile SWCs to the build path. This is using a Flex Project with AIR deps.

  1. Right Click on the Mobile project.
  2. Select Properties
  3. Select Flex Build Path
  4. Select the Library path tab
  5. Click Add SWC…
  6. Browse to the folder approximately in C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.1\frameworks\themes\Mobile\mobile.swc
  7. C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.1\frameworks\libs\mobile\mobilecomponents.swc

Now the project contains the necessary SWCs to create FlexUnit tests. What I ended up doing is since I am creating mobile ui components, I just included my Mobile Library project in the build path of the FlexUnit test application.

I have successfully unit test all my mobile user interface components using this project and the FlexUnit test runner.

Peace,
Mike

Categories: Uncategorized Tags:

AS3 :: ASBlocks :: ActionsScript and Java Dom impls

July 12th, 2011 Michael Schmalle 2 comments

Hi,

EDIT :: This post says that the AST is not adding the second child (IDENT), the parser still parses the UIComponent.as class. ;-) So you can still parse and file right now, just not have access to the recursive field identifiers, the field access nodes are there (the idents parent)

The last two weeks I have been cramming an ANTLR3 AS3.g file for both ActionScript3 and Java implementations. Refactor after refactor bug, learning, all the above going on. Today, I commented the 2000 line grammar, indented all pretty like, sectioned rules logically and thought ok, it’s time mirror over the ActionScript version again.

Since this was a pretty feature complete grammar for the as3 impl (alpha), I was working in Java since the unit testing went about 5 times faster. I have 2000 lines of unit tests (70 tests) for the AS3Parser rules. I have abstracted them so I basically can just copy and paste the Java tests into ActionScript tests.

Ok, this is great, I’m all ready to fire up the ActionScript test suite, now I hit run, flex unit does it’s thing I think I’m going to get all GREEN, WRONG! There were two tests that failed!

This is bad because the two tests that failed have to do with recursive postfix field access and array access. There is something screwy going on with the recursive rewrite rules in the ActionScript version. So now, I have to get some answers on what is going wrong.

The point of this sad story is I am getting so close to an alpha release a for ActionScript (the DOM is implemented Expressions included). So this is a set back for the parsing end. Although for the creation end, say creating field and array access expression through API such as;

var target:IASExpression = factory.newExpression("myObject[42]");
var subscript:IASExpression = factory.newExpression("0");
var aae:IASArrayAccessExpression = factory.newArrayAccessExpression(target, subscript);
// or
var target:IASExpression = factory.newExpression("foo()");
var name:String = "bar";
var fa:IASFieldAccessExpression = factory.newFieldAccessExpression(target, name);

the above is still possible recursively since I use an ASTBuilder not the parser.

The Plan

I will tidy the ActionScript version up, get it ready for an alpha release with this bug included. I am going to spend a large amount of time on the Java branch now. I have this branch implemented to the statement.

Anyway I know there are a lot interested in this project, hold on tight, code is on the way.

The good news is I have the AS3.g somewhat stable, that was an insane trip.

Mike

AS3 :: ASBlocks :: ASDoc parser comes along aswell!

July 5th, 2011 Michael Schmalle 2 comments

Hi,

Just wanted to pass along the fact that along with this great AS3Parser and as3 DOM, there is an antlr parser with linked token implementation and DOM as well.

This means that creating, editing and moving asdoc comments around in an Adobe AIR application could never be easier.

Core Example using the actual parser (not DOM)

private static function parse(str:String):LinkedListTree
{
	var parser:ASDocParser = parserOn(str);
	return parser.comment_body().tree as LinkedListTree;
}
 
private static function parserOn(str:String):ASDocParser
{
	var cs:ANTLRStringStream = new ANTLRStringStream(str);
	var lexer:ASDocLexer = new ASDocLexer(cs);
 
	var linker:LinkedListTokenSource = new LinkedListTokenSource(lexer);
	var stream:LinkedListTokenStream = new LinkedListTokenStream(linker);
 
	var parser:ASDocParser = new ASDocParser(stream);
	parser.treeAdaptor = TREE_ADAPTOR;
 
	//parser.setInput(lexer, cs);
	return parser;
}
 
// impl
 
var body:LinkedListTree = parse("/** Hello world! @author Mike Schmalle */);

The underlying tokens and AST is pure ANTLR API, so there is huge flexibility at traversing and inspecting the AST tree. The use of the linked token list allows for token traversing as well.

The ASBlocks project is aimed to bring a new level of Pure Actionscript/Flex tool applications into existence. I have been working on this project for over 3 years in various stages.

I have heard rumors of some that want to try and use this framework as an ActionScript compiler, we will see.

Stay tuned, I’m getting real close to getting this new branch up online in GIT so you can start experimenting.

Mike

Categories: Uncategorized Tags: ,

AS3 :: ASBlocks :: the future of actionscript3 code creation

July 1st, 2011 Michael Schmalle 10 comments

Hello,

It’s been awhile since I posted anything about as-blocks actionscript3 project. My last year or so has been a little bit about survival on other fronts. :) The as-blocks project started out as a simple as3 parser that converted it’s parse data into an AST. The original intention was to be able to parse actionscript3 for use with a new documentor I was developing (the original parser and lexer was written in Java). As time progressed, I felt a nagging desire to see if I could port this Java parser and lexer to as3. Well months later I had unit tests confirming it would work.

After a long sabbatical this last 6 months, I came back and got my nose back into antlr (I love parser grammar). As metaas was the original inspiration to the AS3 DOM I was developing, I thought I would take a look at David’s AS3 grammar file. Minus a bit of Java entwined in the grammar, I managed in about a week or so to get a working grammar file in antlr 3.3 using the ActionScript code generation target.

What does this mean?

Well the answer is simple;

1. I have an antlr parser and lexer built into as-blocks which is very powerful. The parser uses AST re-write rules and constructs a very well formatted AST from CompilationUnit down. Most of the original API in as-blocks is staying the same(that exists in GIT right now).

2. With this grammar abstraction, I am able to create a parser and lexer in Java which is VERY fast and I am sure a bunch of Java developers would love not only to have an AS3 parser in Java but, a well documented AS3 DOM api in Java as well.

I have decided to mirror the as-blocks DOM into Java in a new project called jas-blocks DOM. Having both of these projects side by side in GIT will create an easy way to update them individually but keeping them the same with grammar.

Current as-blocks code base

GIT Repositoryas-blocks

What next?

I have listed projects in a blog post previous that will use these frameworks. I have also had interest from the dev community about some things they want to create as well. Stay tuned for more updates (GIT currently does not have this new impl, I am working on an alpha release).

Mike

Unity3d :: UML :: Behaviour visualization cheat sheet

June 20th, 2011 Michael Schmalle No comments

Hi,

Here is a detailed UML class diagram of the Behaviour API for Unity 3D.

Basically the action duties of the Behaviour class include;

  • Enables-disables the component

UnityEngine.Behaviour Class Diagram

Categories: Uncategorized Tags:

Unity3d :: ScriptableWizard tutorial 1

June 10th, 2011 Michael Schmalle No comments

Hi,

In this blog post we talk about the Unity3D ScriptableWizard class. I am really enjoying the API adventure into Unity3D but, the API Scripting reference is to be desired. An example of this is the ScriptableWizard description;

"Derive from this class to create an editor wizard. Editor wizards are typically opened using a menu item."

If this description doesn’t leave you scratching your head, then can you please tell me what I’m missing? After messing around, I finally realized that the wizard base class must use reflection on the public properties to create the wizard fields. Why couldn’t they just write one more sentence and add a detail like that. Aside from giving you two button options like the classic wizard, automatic control generation is in the realm of majik as well.

Another problem I had minus the above misunderstanding is the WizardCreateLight example they give is really mixing a wizard with an inspector. For me, this example was really confusing. Most of the wizard classes I have dealt with or written are usually called, filled out and dismissed. The WizardCreateLight example gives you an option to create a light OR apply a new color to the current transform. Applying values to existing instances is in the realm of an inspector. Anyway, that is just my point of view.

Tutorial version; Unity 3.3

Wizard Skeleton Class

In the class below the following can be observed;

  • All public properties will be reflected in order of declaration as wizard fields.
  • The MenuItem attribute will create the menu item "My Scriptable Wizard" under GameObject/Wizards
    • The attribute ties the static method CreateWizard() to it’s command action.
  • The ScriptableWizard class adds four messages;
    • OnDrawGizmo() – Called every frame, updates a custom gizmo in the Scene view.
    • OnWizardUpdate() – Called when opened and when user interaction events are fired within the wizard.
    • OnWizardCreate() – Called when the user clicks the first wizard button.
    • OnWizardOtherButton()- Called when the user clicks the second wizard button.
using UnityEngine;
using UnityEditor;
using System.Collections;
 
// A Wizard class that generates it's fields from public properties
public MyScriptableWizard : ScriptableWizard
{
	//---------------------------------
	// Reflection Fields
	//---------------------------------
 
	// An auto generated field
	public string myGeneratedField;
 
	//---------------------------------
	// Static Methods
	//---------------------------------
 
	// Create the wizard
	[MenuItem ("GameObject/Wizards/My Scriptable Wizard")]
	static void CreateWizard ()
	{
		MyScriptableWizard wizard = DisplayWizard<MyScriptableWizard>(
			"My Scriptable Wizard", "Wizard Create", "Wizard Other Button");
	}
 
	//==================================
	// Messages
	//==================================
 
 
	// Called every frame when the wizard is visible.
	void OnDrawGizmos()
	{
 
	}
 
	// This is called when the user clicks on the Create button.
	void OnWizardCreate()
	{
 
	}
 
	// This is called when the wizard is opened or whenever the user 
	// changes something in the wizard.
	void OnWizardUpdate()
	{
 
	}
 
	// Allows you to provide an action when the user clicks on the 
	// other button.
	void onWizardOtherButton()
	{
	}
}

Wizard Example Class

In the class below shows a pretty close approximation of all the different UserInterface controls that can be created through the wizard’s reflection mechanism.

The example also shows the use of the isValid, errorString and helpString class properties. If the intField has not had it’s value changed from 500 and the textField has not had a string entered, the wizard will be in it’s disabled state. Once those two conditions are met, the wizard’s Create and Apply button will be enabled, allowing the user to click the either button.

using UnityEngine;
using UnityEditor;
using System.Collections;
 
 
/**
 * Shows the following;
 * 
 * - ScriptableWizard.errorString
 * - ScriptableWizard.helpString
 * - ScriptableWizard.isValid
 * - ScriptableWizard.OnDrawGizmos()
 * - ScriptableWizard.OnWizardCreate()
 * - ScriptableWizard.OnWizardUpdate()
 * - ScriptableWizard.OnWizardOtherButton()
 * 
 * @author Michael Schmalle <mschmalle@teotigraphix.com>
 */
public enum TestEnum {
	ONE,
	TWO,
	THREE
}
 
public class MyScriptableWizard : ScriptableWizard
{
	// Note: All public properties that are created as fields will have
	// their names split 
 
 
	//----------------------------------
	// Primitive Fields
	//----------------------------------
 
	// FloatField()
	public float floatField = 500;
	// IntField()
	public int intField = 500;
	// Toggle()
	public bool toggle = true;
	// TextField()
	public string textField;
 
	//----------------------------------
	// Struct Fields
	//----------------------------------
 
	// Vector2Field()
	public Vector2 vector2Field;
	// Vector3Field()
	public Vector3 vector3Field;
	// Vector4Field()
	public Vector4 vector4Field;
	// RectField()
	public Rect rectField;
 
	//----------------------------------
	// Enum(lists) Fields
	//----------------------------------
 
	// EnumPopup()
	public LightType enumPopup1;
	// EnumPopup()
	public TestEnum enumPopup2;
 
	//----------------------------------
	// Custom Fields
	//----------------------------------
 
	// ColorField()
	public Color colorField;
	// CurveField()
	public AnimationCurve curveField;
 
	//----------------------------------
	// Object Fields
	//----------------------------------
 
	// ObjectField()
	public Light objectField1;
	// ObjectField()
	public Font objectField2;
 
	//----------------------------------
	// Static Creation
	//----------------------------------
 
	// Create the wizard
	[MenuItem ("GameObject/Create My Scriptable Wizard")]
	static void CreateWizard()
	{
		MyScriptableWizard wizard = DisplayWizard<MyScriptableWizard>(
			"My Scriptable Wizard", "Create", "Apply");
		wizard.isValid = false;	
	}
 
	//----------------------------------
	// Messages
	//----------------------------------
 
	// Called every frame when the wizard is visible.
	void OnDrawGizmos()
	{
		// Currently on Windows 7, I cannot get this to run
		// has anybody else had this problem?
		Gizmos.color = Color.green;
		Gizmos.DrawWireCube(Vector3.zero, new Vector3(1,1,1));
		Debug.Log("ODG()");
	}
 
	// This is called when the wizard is opened or whenever the user 
	// changes something in the wizard.
	void OnWizardUpdate()
	{
		if (textField == "")
		{
			errorString = "Please fill in textField string";
		}
		else if (intField == 500)
		{
			errorString = "Please change the value of intField";
		}
		else
		{
			helpString = "All fields correct, Create enabled";
			errorString = "";
			isValid = true;
		}
	}
 
	// This is called when the user clicks on the Create button.
	void OnWizardCreate()
	{
		Debug.Log("OnWizardCreate()");
	}
 
	// Allows you to provide an action when the user clicks on the 
	// other button "Apply".
	void OnWizardOtherButton()
	{
		Debug.Log("OnWizardOtherButton(Apply was pressed)");
		Close();
	}
}

The image below shows the completed wizard when called from the menu item.

Categories: Uncategorized Tags:

Unity3d :: UML :: Component visualization cheat sheet

June 9th, 2011 Michael Schmalle No comments

Hi,

Here is a detailed UML class diagram of the Component API for Unity 3D.

Basically the action duties of the Component class include;

  • Broadcast messages to listeners
  • Manage composite scene Component instances registered

Using an analogy, the Component class acts as the GameObject's circuit breaker. All pieces of the scene object are wired through this component class.

An interesting characteristic of the Component class is, although it composites all components into itself, the class is also the base class for all Components. It’s like having your cake and eating it to. There must be a design pattern name for this but, I am at a loss for what it is called.

In the UML diagram all Behavior subclasses are to the left vertical, straight Component subclasses are bottom horizontal.

UnityEngine.Component Class Diagram

Categories: Uncategorized Tags:

Unity3d :: UML :: Renderer visualization cheat sheet

May 30th, 2011 Michael Schmalle No comments

Hi,

Here is a detailed UML class diagram of the Renderer API for Unity 3D.

Basically the action duties of the Renderer class include;

  • Render the current mesh’s materials

The Renderer class makes use of the following;

  • Material (mesh render)
  • Vector4 (lightmap tiling)
  • Matrix4x4 (transformation)
  • Bounds (bounding volume of the renderer)

UnityEngine.Renderer Class Diagram

Categories: Uncategorized Tags:

Unity3d :: UML :: Camera visualization cheat sheet

May 24th, 2011 Michael Schmalle No comments

Hi,

Here is a detailed UML class diagram of the Camera API for Unity 3D.

Basically the action duties of the Camera class include;

  • Render the current Scene through it’s viewport
  • Clip rendering

The Camera class makes heavy use of the following;

  • Rect (camera size)
  • Vector3 (viewport)
  • Matrix4x4 (projection)

The Camera enumerations;

  • CameraClearFlags
  • DepthTextureMode
  • RenderingPath

UnityEngine.Camera Class Diagram

Categories: Uncategorized Tags: