Archive for the ‘ ActionScript ’ Category

Molehill might become a fun, usable mountain

[tweetmeme source=”neoRiley” only_single=false]So, essentially, Unity has entered the Flash 3D world.  While 3D api’s (Away3D is doing an excellent job, btw) might provide a way to bring 3D to life via Molehill, Unity brings a kick-ass IDE with it.

And considering that they’re going to support AS3 right out of the bag (which they practically already do with UnityScript) as well as the other languages you can already use (I’ve become a c# fan myself), I’m hoping the resulting project from Unity will allow for maximum integration with flash projects.  I have no idea what output they intend to target (swf or project to yet be compiled by flash), but I do hope they output a project we can work with on the FlashBuilder or Flash IDE side of things.

There have been quite a few discussions about this move, and as usual, there’s 2 camps – the yay’s and nay’s.  I see it as a positive for Unity overall – they’re in the business of making tools, and they do that extremely well, and without a doubt, their developer base will broaden drastically if the resulting Flash is what people expect and need to get their work done (reference Adobe’s output for iPhone compared to Unity’s – case closed).  Case in point, I’d created a Papervision3D component for the Flash IDE a while back – it was downloaded over 450,000 times).  That tells me that people want visual solutions to 3D problems and that there’s a huge potential user base for a good Flash3D IDE.  Bringing Flash3D to the lower common denominators in the development food chain is a “good” thing.

But without a doubt, Adobe is the massive winner here.  IMO, they are walking away with much more of a win.  The one thing I’d complained about early on was that Molehill left 3D to the egg-heads who loved being the only ones who could use it.  As I’ve said before – until you bring it to a state of usability by the masses, it’s pointless and will largely be fruitless.  In other words, I felt that if the new 3D capabilities weren’t put in the hands of us lesser-folk through a common interface and language, it wasn’t going to go anywhere except for demoscene reels on YouTube.

Enter in Unity, and you just fixed all of that.  All of what I was saying and telling them they needed to achieve, they received from Unity3D (Merry Christmas Adobe).   I do wonder how Unity’s physics, Beast Light mapping and shaders will translate, but I’m guessing those are the fruits they intend to dangle in front of even the most hardened Flash 3D developer 😉

Check out the official release statement:

Coming from ActionScript / UnityScript to c#

[tweetmeme source=”neoRiley” only_single=false]After writing iFly and Star Wars: Trench Run in UnityScript, I became painfully aware of the shortcomings associated with UnityScript.  Mainly that it has no decent event / delegate system to leverage.  Sure, you have event handler methods that exist in GameObject etc, but that’s a complete throw back to AS2/1 days.  I tried porting an old AS2 event dispatcher class to UnityScript (which I did successfully) but had pointed out to me by someone at Unity that it would be painfully slow.  He then suggested I consider c# and get involved with delegates.  He was right.

So, for a while now, I’ve been doing c# and loving it.  There were, however, some things that obviously caused me some discomfort and that’s why I’m writing this post.  I’ll be adding to it when ever I find new topics that apply.

First, here is a link that provides the majority of the “differences” between UnityScript and c# – I recommend this one as it really covers the basics very well.  I’ll be covering the not-so-obvious ones that made me scratch my head 😉

Alright then, here’s the first thing to look out for:

Number = float

Coming from AS3, you’re used to Number, int, uint and for the most part, you get what they do.  When coming over to c#, there is no “Number” type.  Instead, use float.  Just think of it in the most simple terms:  “f”loat for “fraction”.  Meaning, if you know you’re number will be fractional (like 3.16) then give it a type of float:

float myScale = .5f;

Note the “f” at the end of the declaration (.5f) – that’s how you cast it as a float.  If you don’t, Unity compiler will give you an error.  Same goes for passing floats as arguments, make sure you include the “f” cast:

Vector3 pos = new Vector3(.1f, .05f, 2);  // you can add the "f" cast after a whole number if you like, but it's not necessary

If you’re doing some division or scaling math and you know the outcome *could* be fractional, both sides of the equation need to be floats or you’ll get a whole value in return.  Simple enough you might think, but I’ll bet you scratch your head at least one time on this one where you can’t figure out *WHY* it’s not calculating a remainder for you:

float i = 15f;
float j = 10f;
float value = i / j; // 1.5f

If you want to parse a string into a float or int:

int value = int.Parse(stringValue);
float value = float.Parse(stringValue);

If you want a whole number and an int from a float, use FloorToInt() – I mention this one simply because of how AS3 just doesn’t give a crap, but c# does:

int value = Mathf.FloorToInt(float n);

Event Dispatching

In AS3, everything extends EventDispatcher practically.   Everything can dispatch events, have listeners and everyone’s happy in their little event driven world.  Then you come over to Unity and realize, we’ve taken a step back into AS1/2 land. There are event handlers on GameObjects and if you declare them, then they will receive the calls – very very onEnterFrame type of stuff here.

So, given my history and experience with AS2, I naturally dusted off an old EventDispatcher class that we used to use back in the day.  Like I said above, I converted it, it worked, but was made to realize that in a performance setting, it’d be a pretty substantial bottle neck.  Still, if you’d like to see how it’s done, here you go ( now at least, I won’t feel like the time I spent on it was wasted )


But now, the real deal in c# for creating an event and dispatching goes something like this:

Declare a delegate for the event. Note that I’ve created it outside the class declaration – this is so it’s available to any class:

public delegate void LoadComplete(float value);
public class MyClass

Now, create the event in MyClass:

public delegate void LoadComplete(float value);
public class MyClass
public event LoadComplete LoadCompleteEvent;

To add a listener, you add a new delegate instance with the handler to the LoadCompleteEvent event:

public delegate void LoadComplete(float value);
public class MyClass
public event LoadComplete LoadCompleteEvent;
    public void Start()
        LoadCompleteEvent += new LoadComplete(HandleLoadComplete);

    // note how the argument signature matches the delegate declaration
    private void HandleLoadComplete(float someValue)
        // event handled here

To send out the event, first check to make sure the event is not null (has listeners), then call it like a method:

public void DoSomething()
    if( LoadCompleteEvent != null ) LoadCompleteEvent(1.0f);

To remove a listener, just remove the handler from the event:

LoadCompleteEvent -= HandleLoadComplete;

Coroutines (replacement for setTimout, setInterval, Timer object)

In AS3, we’re used to setTimeout() or the Timer object to deal with waiting and looping stuff.  In the old days, we used onEnterFrame and I can still remember the arguments over which was better – setInterval or onEnterFrame.  It was a ridiculous argument, because in reality, it just depended on *what* you were doing when that even fired.  Please don’t leave comments regarding this tired and exhausted discussion which has zero relevance these days 😉

In UnityScript, you’ll be introduced to WaitForSeconds() which is really nice when coming from AS3.  In c#, however, you get a bit of a rude awakening. You begin to realize how much UnityScript lets you get away with.  Its insane.

So, here are the basics.

If you want to loop or wait a certain amount of time, you have to call a method that returns IEnumerator:

public IEnumerator DoMyBidding() {...};

Then, you have to have some sort of yield/return statement in this method or the compiler with barf all over your keyboard:

public IEnumerator DoMyBidding()
    yield return WaitForSeconds(1.5f);
    if( myConditionNotMet ) yield return null;  // this is how you just simply return out if you no longer wish to continue.

If you want to loop something:

public IEnumerator MonitorMe()
    while ( conditionNotMet )
        // do something
        yield return WaitForSeconds(.025f);

To call these methods, you have to use StartCoroutine():

public void Start()
    StartCoroutine( MonitorMe() );

Well, for now, that’ll get you started, and as I remember/think of things, I’ll come back and update this post with more tid-bits.  Enjoy!

Do developers drive the market?

[tweetmeme source=”neoRiley” only_single=false]I’ve heard several different ideas over the past week about what we might do and what we ought to do as developers (and consumers) to teach Apple a lesson about section 3.3.1.

Everything from “post everything you have to the app store” for approval, to purchase every app known to be made by a 3rd party app, to stop developing for iPhone / iPad all together ( as I type this out on my new iPad ). Personally, I don’t think the first 2 are going to make a difference that apple would see or much less care about.

So I was thinking about what Mike Chambers posted about yesterday. He states that he’s going to focus on android and is looking forward to the tablets coming out later this year. He then goes on a bit further about not going forward with any iPhone development to the point of not even maintaining the apps he’s already put out in the apps store.

While I can certainly appreciate where Mike is coming from and his reasons, I think that it’s premature for one, and I think ultimately we as developers should never burn technical bridges so to speak. Not that I have any idea whether or not Mike will ever do OC work again or not, that’s beside the point. And to be fair to Mike, his job doesn’t require him to keep OC in his back pocket – that’s not his job.

My question is: what drives the mobile market anyway? Is it the will of the developer community? Or, is it based on what the consumers want? Simple enough, right?

If you think it’s driven by the developer community, you’re wrong. It’s driven by the fanboys and fangirls who have no clue what’s going on behind the scenes – they see new toy, they buy new toy as long as the experience is good. And right now, the iphone IS the best mobile phone experience out there. This is mainly to do with the fact that Apple IS so anal. Just look at every other phone being developed these days. The phone makers are responding to a public that loves the experience of the iphone. Look no further than android for an example of that ( case in point Nexus one which looks like your dad’s old palm pilot compared to an iPhone IMO )

Bottom line – there’s a need and market for iPhone and iPad apps right now, and this means we have a demand. As long as there’s demand, someone’s going to step up to the plate, take the gig, and make the money. Simple as that.

So with that, I would encourage any developer out there to not abandon technology for ideology. What comes around goes around, and we’ve seen it way too many times already in our short history. Today’s hypocrite is tomorrows hero and in the end, whatever the consumer wants, the client needs. And whatever the client needs, the developer should be able to provide to stay competitive.

NEW: Papervision3D Component 2.1

I’ve just posted the latest version of the component for the Flash IDE:

It’s been a long long wait and I’ve been handing the component out at Flash conferences and classes that I’ve taught, but was waiting for Flash CS4 to be fixed to work with my component.  CS4 has alot of known issues with components, Adobe is well aware of the issues that cause my component not to work and I’m sure it’ll be fixed down the road sometime.

So for now, the component will only work in Flash CS3 IDE.

New Features and bug fixes:

1.  new Materials panel – now you can deal with your materials through this panel that Andy Zupko added oh so long ago 😉

2.  Code Templates:  I’ve put in 2 templates for writing code against the component all flushed out with all the event listeners etc.

3.  Many bugs fixed

Thanks all, and enjoy!


Flash on Tap Slides:

Flash on Tap was a GREAT conference – unbeleivably cool and laid back (at least for me it was).  It was truly great to see old friends again and hang out a bit.  Last time I went to a conference I was so stressed about about getting hours in on a project, I couldn’t enjoy Brighton.  It was a shame really.  But this time around, I really took the time to enjoy myself and just do what I wanted.  The class went great on Thursday, and the 3D panel discussion today was very cool.  I was nice to get to voice some opinions about about Flash, Unity and 3D in general.

Anyway, I rushed through my Papervision to Unity to iPhone session like mad at the end and promised I’d post the slides, so click on the image above or here.  I’d clearly planned to talk about way too much in my presentation, but I was at least able to do the sample demo app I’d put together of the obstacle course.  I was happy that people enjoyed seeing Unity in action and creating a simple game, but was bummed I didn’t even get the chance to show some scripting so they could see how very similar Unity’s Javascript is to ActionScript3.

There’s always next time!!

Papervision Training at Flash on Tap

Man, I was just over at Keith’s blog and saw him realizing that FOT is just 3 weeks away!!! I instantly had the same reaction – holy beer batman!

I thought it’d be good a good idea to post what Andy and I will be covering and what you’ll need.  We’re giving a live full day workshop the day before the event starts.  If you haven’t signed up and you’re interested in going to the 1 day work shop (you don’t have to attend FOT for this), email me at neoriley at gmail dot com and I can get you the same $70 off discount code.

What we’ll be covering:

John first half of day:

  1. Papervision basics – scenes, cameras, setup
  2. cameras and animation
  3. Primitives
  4. Materials
  5. Collada
  6. Papervision3D component for Flash IDE (requires CS3 unfortunately)

Andy will cover:

  1. Effects and Layers
  2. Effects Filters
  3. Shaders

The class has filled up nicely I so far and I’m really glad to get out and teach again.  Its something I really enjoy doing

Change to my Session at FOT

It was a year ago when i’d put up my description for my Session at Flash on Tap and I’d really intended just to follow through with that, but now that we’re getting much closer to the actual event, I think my topic is really not in sync with what I’v been working with in the past 6+ months.

So, I’m going to be covering the development crossovers between Papervision/actionscript3, to Unity3D/Javascript, to iPhone 3D gaming.  I’ll be showing the differences and similarities between Papervsion and Unity3D and talk about the caveats to iPhone 3D gaming with its abilities and limitations.  I’ll also being showing the Unity3D IDE,  features and workflow.

Stunt Bike iPhone game in Unity3D IDE

Stunt Bike running on iPhone

Many of the issues we deal with in Papervision3D are applicable to the iPhone 3D gaming development.  With Unity as a middle man for development, I think there’s plenty to talk about 😉

Hope to see many of you there!

Seb’s Papervision black hole

THIS rocks!  I just had to give a shout out to Seb for giving me my first Papervision3D inspiration of the year!

I’d try to explain it, but I think you should just check it out for yourself 😉

Unity3D \m/’s – Adobe should buy them.

I know it’s been a while since I last posted, and I have a REALLY good reason for it 😉  You see, Andy Zupko had been dropping comments here and there about how he’d wanted to do Unity3D work.  First couple of times I heard him say it, I was thinking “yeah yeah flash master Andy, what’s this unity thing anyway?”

Well, I finally asked him what Unity3D was and he pointed me over to and then showed me their Tropical Paradise demo and my jaw began to hit the floor.  This was a web plugin?  holy polygons/lighting/shaders batman!

Tropical Paradise - Terrains, streamed terrainse

With OpenGL and DirectX support, this little web plugin ROCKS.  It’s a complete game development tool that allows you to code in JavaScript, C# and a dialect of Python called Boo.  The JavaScript is strictly typed and compiles to native machine code – it’s just as fast as C# or Boo.  Not to mention 20x’s faster than Flash’s ActionScript.  And for me, getting into Unity took practically ZERO time.  I was up and importing FBX (you can export as FBX from 3D Studio Max) models and practically doing what I do in Papervision3D with very little effort!  In fact, moving some of my classes over to Unity for this game that Andy and I are working was a matter or some simple refactoring to accommodate Unity’s api.

Now, before we start getting totally OHH and AHH over this, let’s take a look at the discussion that’s already on your mind probably at this point in the post:  Why can’t FLASH/ADOBE have this?!?  I know, cause I was thinking the same thing 😉  The answer might be something like “I don’t think there’s a good reason anymore”.  It USED to be a really big discussion about player size.  I remember back on Flash6 beta, I was begging for w3d support since you could use those files in Director at that time, and they were fairly lightweight.  But the argument was around hardware support and player download size.

But check this out:

Flash player download = 5.5mb
Unity3D web player download = 4.5mb

Ding.  Round one over.  The winner?  Unity3D.

Ok, so is that a fair comparison?  No, not really, but in the argument about the player growing in size seems to be greatly reduced from the days of a 700k Flash player plugin download.  I realize that 5.5mb + 4.5mb = a bit more of a struggle to convince people to download, BUT, I’m SURE there’s a conversation that could be had about loading and running SWF’s into Unity3D like Director does.  Yes?  Did I mention Unity3D is cross-platform compatible?  Publish standalone builds for Mac OS X (Universal Binary, or specific, smaller Intel/PPC-only builds) and Windows 2000/XP/Vista – OH and then put it on the web…cause you can.

If that wasn’t enough to sweeten the pot on Adobe buying out Unity3D – Unity3D does iPhone apps with a single click ( watch the Demo Movie of the iPhone development setup – that’ll sell you right there ).  Hmmm I love me some iPhone 🙂  Not enought??  How about Wii Development?!  BAM!  NOW WHAT?

Terrain, Shaders, Physics, Lighting, Cross-Platform, multi-depolyment option, multi-lingual, Game churning tool!

Have you ever found yourself saying: ” I wish Director used Actionscript – if it did, I’d move right on over to it and develop there!” Well, ok, maybe that’s too drastic and silly, but Unity3D gave me more power than Director and it was extremely easy to get into – the “power” here is that it is realized and made available to *me*.  I’ve had access to Director for nearly 10yrs now, and not once did feel like I could get into it easily.  I realize you can do Javascript now (Lingo was an abomination), but after my bad experiences in the past, I wasn’t willing to get into the the Director mess again.  I saw Unity for 5 minutes and downloaded it instantly. Unity’s IDE rocks – flat out.  It’s fairly easy to understand, and debugging 3D scenes at runtime is awesome.  You can have the scene up top with the game running below and you have access at runtime to really dig through and manipulate all objects and properties at runtime (hmmm… where have I heard that before…XRAY 😉

Unity3D IDE

One of the other nice things is that you can configure TextMate with a Unity3D bundle for editing.

I think I’m a fairly good indication of what *could* happen when other Flashers like me get a hold of Unity3D.  I hope Adobe’s listening 😉

With all of that, combine the fact that SilverLight is working hard to compete with Flash and they have access to DirectX – it won’t be long until Adobe see’s they need a kick-ass solution.  THIS one actually works cross-platform with a ton of speed, easy adoption rate by the development community and a smaller player download size than Flash.  Either they’re already looking at Unity3D as I type this post or they soon will be.

One other thought I had is that, I’m not sure the Flash player is going to keep up or IS keeping up with the abilities of hardware that have been out for a while now.  I can see where they’re going with Pixel Bender etc, but I know I wasn’t the only one disappointed with what came out in FP10 in terms of hardware acceleration etc and so on ( I don’t need to restate what others have already said ).  I think that’s exactly what draws me to Unity3D – total frustration over speed/performance.  With Unity, it was like a massive breath of life for me in terms of developing games and playing in my own time.

Avert Fate - Particles, physics, ragdolls, image effects and custom shaders

So, let’s put our money where our mouth is, shall we?

By now, you know I work for Infrared5 with a ton of great developers.  If you want Flash / Flex / Red5 work done, we can do it. Duh.  But what about iPhone development?  what about serious game development?  What about product/marketing efforts that need more than what the Flash Player can give us in terms of power?  Where would we turn?  Well, we’ve officially added Unity3D and iPhone game developement to the list of services BECAUSE of Unity3D.  Considering that any one of our developers can get up to speed in a matter of an hour or less, it’s a no brainer to expand our service base.  SO, if you’re in the market for iPhone game development or app development, let me know, and I’ll get you in touch with the right people 😉

Given how well many iPhone / iTouch apps are doing in the app store with Apple, I think there’s a bonanza of opportunity there – HUGE.

Ok, so the payoff for even posting this…post, is that I wanted to FINALLY show a few screen shots of a game I’d story boarded 4yrs ago and promised I would produce wayyyyyy back in 2002 (8/16/2002 to be exact) when I released my first Star Wars game – Escape of the Falcon.  I’m not going to show too much, but you guys and gals need to see I’m serious about what I just typed above.

Escape of the Falcon

Original Star Wars game: Escape of the Falcon

Web Version of the Trench Run

Web Version of the Trench Run

And Since Keith was showing off his iPhone Gravity fun, I wouldn’t feel right not sharing since he mentioned a Star Wars game 😉

iPhone Trench Run - low poly trench model

iPhone Trench Run - low poly trench model

I have to thank Andy for getting into Unity though! I don’t know that I would have heard of it or gotten into it if he hadn’t pointed out the obvious to me 😉  To say the least, he’s in hog heaven with real physics, custom shaders and streamed terrains!

I seriously suggest that if you’re into 3D, Gaming and Flash right now, you should try Unity3D.  And yes, I fully expect that I’ll drive SO much traffic their way that they’ll give me a license 😉  Thankfully, IR5 got me one !  LOVE YOU CHRIS/REB/DOMINICK!  LOVE you.  Man love.

And Finally:  Adobe – if you’re reading this, you guys should seriously consider buying out Unity3D.  I can’t say it any more plain than that.  If you don’t, I don’t know how you’ll COMPETE with them.  As soon as they’re able to support running SWF’s in Unity, i’m going to be doing alot more work over there 😉

How to detect when a TextArea is full: Paging

Well again, this is for archive and maybe it’ll save someone some time 😉 This is a screenshot of a test with the code below. It has 2 different TextArea components with differing fonts and font sizes that page the text perfectly between the 2 controls.

if you’ve ever tried to do paging or find out how many lines were being occupied in a TextArea’s TextField, this is one way to accomplish the task that seems to work every time. It’s pretty straight forward in that you just need to get to the TextField object that the TextArea uses. Simply test maxScrollV after calling validateNow on the TextArea and bam, you’re in business.

import flash.text.TextField;

import mx.controls.TextArea;
import mx.core.WindowedApplication;
import mx.core.mx_internal;
//use namespace mx_internal;

public class BasicApplicationTestBase extends WindowedApplication
public var t0:TextArea;
public var t1:TextArea;
public var txt:String = “Well, it’s not secret that Papervision3D has taken the Flash world by storm, surprise and to the next era of Flash design and development. It’s become a regular word in the arsenal of any Flash designer and developer around the community and we’re really excited about being apart of that! One of the cool things about having an impact like this is the attention Adobe started to give the 3D API’s that were emerging.”;
public var words:Array = [];

public function BasicApplicationTestBase()
addEventListener(AIREvent.WINDOW_COMPLETE, handleComplete, false, 0, true);

protected function handleComplete(e:Event):void
// split up the string at the spaces
words = txt.split(” “);

public function doIt(e:Event=null):void
// set the target textArea
var target:TextArea = t0;
// clear the current text
target.text = “”;
// set the target textArea’s textfield
var textField:TextField = t0.mx_internal::getTextField() as TextField;

for( var i:int=0; i 1 )
// set back to original before changing the target
target.text = originalText;
// set new target TextArea control
target = t1;
// set the word we’re on to the new target, or else we loose it
target.text = words[i] + ” “;
// set new TextField object
textField = t1.mx_internal::getTextField() as TextField;