Skip navigation

Category Archives: flash

For a change, this month’s LFPUG didn’t actually feature any Flash. Instead, we were presented with an introduction to iPhone application development with two single-hour talks delving into developing with Objective-C and the Cocoa Touch environment, but all specifically tailored to take an approach designed for a Web developer’s perspective.

I really don’t know how I feel about iPhone development, as a Flash developer, anyway. There’s been a lot of ‘iPhone for Flash developers’ or ‘Actionscript for the iPhone’ or similarly titled tutorials spring up around the Web lately, which I guess have come about on the back of the over night success stories from applications booming in popularity and the ease with which the App Store lets a small dev team get equal distribution and visibility of their application. But why Actionscript?

The profitability is understandable, I just think it’s strange that specifically Flash developers assume that iPhone development is something they can or should be laying claim to, that it’s something within their domain or their right to be creating these apps? It’s gotten to the point where a Flash platform meeting is hijacked (hijacked isn’t the right word, it wasn’t unwelcome and it drew the biggest turn out I’ve ever seen) – is it selfish (?) that there’s such a demand for tutorials to be made easily digestible for them, when traditionally any other kind of development is usually approached by everyone else peaking in?

I’m not sure, I can’t decide. Maybe it’s more honest – that instead, for example, it’s the look and feel, the slick presentation layer and the interactivity of the interface that’s so attractive (it’s Flash-like) – and a lot of people do start playing with Flash because it looks good. Flash is inherently a visual platform. Maybe Flash just is the closest platform and Flash development easily lends to iPhone development.

Whatever the case, thinking as a platform-agnostic programmer, I was looking forward to the meeting. I have an addiction to learning (or trying) new languages even if I needn’t, plus it was honestly disclosed that this week there would be no Flash content an iPhone 101 bent into shape for Flash developers to understand, it would be was tailored for Web developers generally – I was hoping for more conceptual comparisons rather than perhaps just pointing out syntactical differences – either way, curiosity had the better of me.

First up was Masi Woermann starting with An Introduction to iPhone Application Development. He introduced the broad concepts of iPhone development and the different approach developers must under go to create applications mainly looking at the workflow. Being primarily a Flex developer, Masi maintained comparisons between the architectures of a Flex app and an iPhone app – drawing parallels between Objective-C and Actionscript coding and their relationship to the UI components created with Interface Builder versus MXML.

He introduced the development tools and iPhone SDK, discussed some basics of Objective-C (pointers, memory management, classes) and eventually produced a very simple application – demonstrating the basics of interacting with visual components, straightward methods, getters, setters – some simple OOP.

It was good to see some hands on coding and that, obviously, although it’s a completely different kind of development – it might be intimidating but it’s not impossible. Watch it here:

Masi Woermann - An Introduction to iPhone Application Development

Then Matt Biddulph presented iPhone Development for Web Developers. Matt is primarily server-side developer working with the likes of Python, Ruby and Rails, but instead of going into any code expressed that his real interest in iPhone applications lies in the device’s connectivity, specifically the capability to connect to the Web and interoperate and network with data and objects found there.

He looked at the applications that Twitter and Facebook developed, quoting Joe Hewitt‘s development wisdom with his work at Facebook.

He also criticised some of the failures of the current SDK, as Hewitt also did, specifically that some of the native features that you’ll see in Apple’s applications still aren’t available for third-party developers to utilise. I hadn’t realised this was the case, or would have thought Apple would hold back on anything – I guess with later releases more features will become available. The iPhone OS 3.0 SDK is due for release this summer, perhaps more will become available then.

Watch Matt’s talk here:

Matt Biddulph - iPhone Development for Web Developers

Matt also mentioned Phonegap, an open source cross-platform mobile framework for building apps with JavaScript. It’s been labelled as being ‘like AIR for the iPhone‘ and operates on Android and Blackberry, too. Again, maybe it’s just be another means to cut a corner and not develop with the native environment, but it looks impressive – and it seems powerful. You can take advantage of all the core features of the various platforms – geo-locations, the accelerometer etc.

It’s also created entirely by by Web developers. As the video on their site claims, there’s not many Objective-C developers but there are a lot of Web developers – so in keeping with the rest of these observations, there really are more and more opportunities and points of entry for Web developers to get into mobile and iPhone app development, it’s purely demand that has created these.

All in all, whether it’s ‘in favour’ or not for Flash developers to want to develop iPhone apps is probably irrelevant – whether its a for profit or to expand a skillset probably doesn’t mater either. Hopefully all the attention will cause a shift in the perception of developing for mobile devices in general, I know I still cringe whenever anyone mentions Flash Lite – but it seems that’s starting to enjoying the beginnings of a resurgence too.

Then I think of initiatives like Adobe’s Open Screen Project and think this could be a really exciting time for mobile devices regardless, maybe there’s just so much fuss over the iPhone right now because it’s the iPhone.

As I write this post an email has just arrived in my inbox announcing there’s new group meeting specifically for developing iPhone, the London iPhone Bootcamp – ‘part seminar, part hackathon, part workshop’ – they too, are looking for the next killer iPhone app!

Thoughts?

Advertisements

Last month I talked about Ted Patrick‘s “Facebook on The Flash Platform“, an Adobe eSeminar discussing development with the Facebook API using Flash. In particular, I pointed to an open source Actionscript API library to work with in the absence of Facebook themselves offering ‘official’ support as they (then) did only for PHP and Javascript development.

This week though, Adobe and Facebook announced a partnership they’d managed to keep neatly under wraps and have now released a new official open source client library for Actionscript 3.

This joint effort is intended to be a complete resource supporting all Facebook APIs, including Facebook Connect, for all Flash and Flex applications for Facebook.

Over on the Adobe’s Facebook Developer Connection, Adrian Ludwig (Adobe) and Josh Elman (Facebook) talk about the library and the partnership. There’s also documentation, example applications, quick starts, inspiration and code.

Adobe Flash Platform - Facebook Platform | Adobe Developer Connection

In his post, Serge Jespers points to a nice quick start by Danny Dura that uses the library to set up a simple connection to Facebook in about ten minutes.

You can tell both Adobe and Facebook are excited about this, adding social elements to games, user experiences or interactions makes them endlessly more engaging, it almost goes without saying. But now that these experiences can be as easily enabled – and in my opinion, enhanced – by Flash, I hope will prove to facilitate some great applications.

It’s equally beneficial for Facebook and Adobe. It means even more applications for the Flash platform and an easily entry point for yet another set of developers to integrate with the Facebook API.

And to help kick that off, Rich Tretola at InsideRIA has announced a new series of articles covering development with the new AS3 library, authored by Mirza Hatipovic – an ambitious 20 articles, from a simple Hello World to advanced PHP and database-supported applications.

I’m particularly looking forward to seeing and playing with the Facebook Connect API – not sure if InsideRIA will cover these – but hopefully whatever I do get up to, I’ll get round to writing about.

Ted Patrick has posted a recording of his Adobe eSeminar “Facebook on The Flash Platform” that he presented last Thursday.

Josh Elman, Facebook Platform Project Manager, joins him – offering a little technical history and strategy behind the application platform and Facebook Connect also.

Facebook on The Flash Platform

It’s a good introduction to building Flash applications using the Facebook API. It’s clear that building on the Facebook platform grants developers an equal opportunity to create powerful and successful social experiences.

As Ted and Josh describe, by utilising Facebook users’ social contexts and by the ease of which you can distribute through the social graph, applications can generate a huge amount of traffic – and as Josh puts it, developers can profit wildy. 😉

Ted gives a simple overview of the architecture of a Facebook application, the various application states and talks about FBML, Facebook’s XML mark-up – and shows how to build a simple single-component Flex application that really demonstrates how easy Facebook have made the information retrieval possible via the API.

The Q&A is worth listening to (it starts around 37 minutes), Ted and Josh discuss important development aspects outside of the actual coding – how hosting is managed, handling session keys and such.

But Ted also points to a promising looking Actionscript library designed for Facebook application developers, simply called The Facebook Actionscript API – which definitely sounds worth checking out (no pun intended).

As yet, Facebook only ‘officially’ support their PHP library, but continue to work with developers in the community to support the other languages. Josh claims this will only improve over the next couple of months and through the year – hopefully (it sounded) to develop similar ‘official’ library counterparts.

Ted’s also posted his Facebook on The Flash Platform sample files.

Yesterday I visited Flash Camp London ’09, an all day community-run Adobe sponsored event on all things Flash Platform.

Last September I attended Flex Camp ’08, (essentially the same, but obviously focused on Flex) so I expected much the same – cool demos, sneak previews, maybe some insight to what Adobe have in the pipeline for the future – and got pretty much exactly that.

Flash Camp '09

Serge Jespers‘ opening keynote held a lot of optimism and promise for the future of the Flash Platform, quoting the huge number of downloads to date and pointing to the constant growth in market share that the Flash Player and AIR are enjoying – throwing in a couple of digs to the various doubters in the sums while he was at it.

He spoke about the Open Screen Project and Adobe’s ongoing aim to achieve a level of open portability across multiple platforms – not only in the browser and onto the desktop, but to mobile devices too and television platforms. On the subject of the mobile platform, he discussed prototype versions of Flash Player 9 (and 10?) running on a few devices he had to hand (though unfortunately no demo) and expressed Adobe’s wish to have those ready for manufacturers by the end of the year, with intention to have them consumer ready for the end of 2010.

Seb Lee-Delisle was first up, showing off some of the Papervision work he’d recently completed with his agency. He also had some nice demos of the augmented reality tutorials that have been going around lately. These usually use nice applications of the ARToolKit, but Seb pointed to a Flash port I hadn’t yet come across called the FLARToolKit. Presumably with which, you have full control via Actionscript. The Papervision blog has a pretty cool example of the kind of things you can achieve with it.

Next up was Michael Chase, Senior Creative Developer at AKQA. He presented his latest work, Nike Football, which involved a lot of work with Pixel Bender – the new video processing and visual manipulation platform available with Flash Player 10.

Pixel Bender is a non-destructive way to manipulate the pixel data of images and videos by means of developing bespoke plug-ins that function in Flash in a similar way to the various visual effects and filters do in Photoshop or Illustrator.

He demonstrated the Pixel Bender Toolkit, the GUI software used to create these filters. It’s purposely almost identical to every other program in the Creative Suite. Adobe are really pushing for seamless integration across the whole family of software for creators – the vocabulary, workspace, tool sets – all feel very familiar.

For the Nike site, Michael basically developed one filter for use across all video and image content. This seems straightforward enough, but it’s an brilliant advancement only made possible by using Pixel Bender. This way, there’s no need to render of every piece of video with the filter on – or subsequently re-render when the filter is inevitably tweaked (which, of course, could only be the case if permission was given to manipulate supplied video footage in the first place). It also means the video filter doesn’t have to be designed by a creator skilled in After Effects or other video editing software – as said, the Toolkit handles very much like Photoshop, which most designers are fluent in – I think Michael said you could actually use Photoshop to create filters anyway.

It also means you can change the single filter once and apply the changes to all the assets rather than having to edit every piece individually – and as he suggested, not having manipulated the source material means the un-filtered source can be reused elsewhere. And of course because it’s just Actionscript before it’s compiled, the whole plug-in script can be manipulated by a Flash developer.

It was good to see this in use, I’d only really seen the default demo ‘Swirl’ effect that a lot of others there also seemed only to have seen (I’m not sure of the real name). That ‘swirl’ is so drastic it seems to have no possible use case, so I’d not really considered Pixel Bender since. Here though its use is subtle, well executed and well placed – I’ll have to give it a go.

Mike Chambers then discussed ‘Scripting with Actionscript 3.0’. Though relatively well-covered territory for the developers, he set about debunking popular misconceptions of Actionscript 3, going through the benefits of migration and giving some examples.

He started with a little background on the new Actionscript version, discussed how the Flash Player was hitting the limits of performance that AS2 could achieve, that Actionscript 3 was heavily driven by the need for application development – which by that point a lot of (the now) RIA developers were forcing into Actionscript 2. They also had Flex in mind.

As I agree with him, ultimately, AS3 isn’t that different to AS2, but it is just different. It’s not harder, or ‘slower’ per se. On a language level, the syntax is still simple and very much the same – it’s the APIs that might present more difficulty for those migrating. The APIs in Actionscript 2 grew organically, expanding where needed, but unfortunately did so inconsistently. It’s that realignment that’s a larger change to overcome.

Arguably, any developer with OOP experience, where consistency is promoted, wouldn’t struggle. He suggests that learning Actionscript 3 is future-proofing yourself for new languages that will be far more digestible now that Actionscript contends as a stronger language.

The Timeline is not Evil!

With that in mind, he did admit that the way Adobe present Actionscript 3 can be somewhat intimidating to those without that kind of basic knowledge. The documentation is very much aimed at developers – the code examples are in class and package structures, assuming programming experience where the previous help documentation never did.

Timeline coding is still possible, easily, but it isn’t documented anywhere near as much as class structured code. With one or two caveats, it actually works in almost exactly the same way.

As well as the ‘future-proofing’ mentioned, Actionscript 3 heralds a whole load of other advantages. It’s more verbose (probably where the argued ‘slower development process’ claim lies) but in that, offers better debugging – the compiler can be set to be more strict and to detect errors earlier, even – and it’s also the language for new libraries and APIs (think Papervision, Alchemy, the many tweening engines) both from Adobe and efforts from the community.

Richard Dean presented his work on the EA Spore microsite, specifically his efforts built using the Inverse Kinematics and 3D of Flash CS4 – demonstrating some nice timeline-based animation effects, the use of the new ‘Bone’ tool to build character skeletons (more about this later) – as well as some handy tips and best practices.

James Whittaker‘s presentation ‘Your First Custom Chrome AIR App With Flash CS4’ delivered exactly what it said on the tin. He offered a walkthrough on how to build your first AIR application, how to design a custom chrome and the various provisions that must be made in doing so, up to publishing an AIR application file and customising the various settings in the new CS4 GUI. He also spoke about handling icons, digital signing, then creating a nice installer badge at the end. His presentation files are already up online.

Lee Brimelow had a huge amount to say about the new CS4 version of Flash – apparently trying to cram a whole day session into his 45 minute slot. He spoke about the new animation model in Flash, how it’s more like After Effects now – again, the overlapping of software uses in the Creative Suite – how even the timeline in the standard workspace is at the bottom of the screen, more along the lines of video editing software.

So much more of the animation process is automated now, to great effect. Motion paths are automatically constructed, even for simple tweens. The path can be treated like any other line in Flash thereon, allowing curvature, adjustment of Bézier angles. Adding a keyframe and point in the middle of a tween no longer creates an awkward corner, but a curve to compliment the original motion path.

There’s far more control. The tween itself is handled as a unique object, so moving or resizing or changing the length of an animation is much easier and also independent of the clip being tweened – there’s no more clumsy attempt to select multiple frames to modify a complete tween.

Again there was demonstration of the native ‘3D’ in Flash Player 10. Lee couldn’t emphasise enough though, that these is intentionally simple 3D effects for transitions and such – not for full 3D immersive environments, for which he recommends to look to Papervision or similar. When the 3D tools are in use though, it’s seamless. There’s a tool to rotate by the Z-axis as simply as there is one for the 2D axes – in doing this, Flash starts to look like 3D rendering software.

These renders are possible because of the ‘notorious’ inclusion of a constantly-running Flash Player on the stage – it’s how Adobe have addressed differences seen in author-time to run-time. In having an constantly running instance of the Flash Player, there should be far fewer discrepancies – although, as they are fully aware of – is a memory hog.

Lee also pointed out the code snippets panel Flash CS4 offers – something I thought Mike Chambers would have mentioned. They’re basically small templates of handy bits of code that anyone unfamiliar with Actionscript (or Actionscript 3, for migrating developers and designers alike) to add common bits of functionality – mouse or frame event handlers for example.

Again we saw Inverse Kinematics – these are great for character animations and (I think perfect) for mocking up prototypes when realistic proofs are required but perhaps the resource isn’t available to fully code them. They’re very quickly put together but equally very effective. Simply constraints applied to skeleton joints create faux-physics that look very convincing. Have a look here if you’ve not seen these in action.

All of that is possible with zero code. Also, all the drag-drop manipulation possible at author-time can also be translated for the user to play with at run-time with the tick of a box – still, with no coding.

Finally Lee demonstrated the new motion editor, which has also has given a huge amount of control to the author compared to what was available before. The complexity of a tween (whether an ‘x’ position or alpha value or whatever) can now be broken down into multiple channels of manipulation.

For example, previously the complexity of control over a tween was determined (and limited) by the tweening graph. This remains, but now different types of easing can be applied to the different parameters within that graph. Say a clip was moving diagonally across the stage – the horizontal movement could have an ease out whilst the vertical direction may have an elastic easing (or obviously any combination). All the tiny tweaks and nuances to animations that couldn’t be easily achieved in previous versions of Flash, or even those only achievable by code now look entirely possible on the timeline at author-time. Lee’s tutorial is a must-see.

Finally, Serge returned to discuss ‘Flex workflows with Flash CS4’. He demonstrated some good techniques in working across Flash and Flex within single projects – firstly how to use Flex metadata tags in Flash, then how to create classes using the Flex SDK and compile those as Flex Library Projects to use as SWC files within Flash (and the Flash CS4 use of SWCs is so much better – adding files to the library rather than to the classpath list) – then likewise compiling components in Flash to handle in Flex. The latter also maintains coded methods on the Flash components that can be handled within the Flex projects, easing the workflow between Flash and Flex developers no end.

Similarly, to ease the workflow between developers and designers (and as I thought would get a mention), Serge ended by demonstrating Flash Catalyst (previously ‘Thermo’). He created Flex components from Flash graphics, multi-layered PSD files and Illustrator assets – all of which generated MXML code that a developer can play with later.

All in all, a great session – Chester and the guys were never going to disappoint. 😉

Various content online can be found in a number of places if you look for the ‘flashcamp_uk’ tag – there’s a whole heap of conversation on Twitter, I expect photos on Flickr and videos on Youtube and Vimeo will surface soon enough. I’ll also put up links to presentations files and source code as and when they find themselves uploaded online.

Update (09.03.09): Serge now has a video tutorial over on his blog demonstrating how to use simple Flex Library Projects in Flash.

Whilst I’m on the subject of Google and trying to finish half-written drafts hanging over from last year, I thought I’d briefly mention the release of Analytics for Flash.

Aside from capturing all the obvious generic statistics you’d expect from a Flash tracking package – and by being fluidly compatible with the main JavaScript library is capable of outputting all the core functionality of the existing Analytics components – the metrics offered by Google Analytics for Flash can be particularly designed to offer interesting insight into other aspects of your users’ activity you may not first expect. For example, you can collect data that can help you gauge levels of usability or (kind of) the implementation of design success. Seemingly you can monitor the behaviour of the users’ interaction during their visit too – as well as the length of the visit itself.

It’s all technically possibly, with Google’s introduction of event tracking that can be fired from custom interactions – whether that be a button click or video view or anything else. Along with that, the event can carry a payload, later received by your Analytics dashboard for your interpretation. It sounds simple – but it’s capable of being very powerful.

Previously, tracking your Flash content would be in isolation. That is to say, you could fire a tracking event when a user accesses a page of Flash content, but from there you were blind to their progress until navigating again.

This payload though, not only could detail traffic to specific sections within a Flash application (although in turn, separate events could be created for those) but could return data specific to that user and session. For example, the total time the user has spent in a particular place, or the site as a whole.

Depending on how complex you wish to be (and how many stats you want to trawl though later) this could offer very valuable data. But that data need not only be of value to an agency or advertiser. Counts for clicks on specific buttons aren’t anything new when you want to find out how many people click a ‘News’ link first, or if anyone notices the ‘Help’ button. This can be far more granular – to the point, as above, where the data could be used to inform decisions on say, design or usability.

Take a standard Flash video player as a media component you’re used to seeing on a daily basis. You can easily picture the common control bar. But how many people actually use those ‘Rewind’ and ‘Fast forward’ buttons? Could the design be improved?

Admittedly with Flash video components, you’re unlikely to see those nowadays 😉 – but that (as I’ve picked this example) is the result of user testing, something this kind of tracking can’t replace – Jesse Warden has a strong sense of this in his post about Flash Analytics.

Anyway, the custom events let you send as (overly-) complex amount of data as you wish. Flash of course can be used everywhere, deployed as widgets or embedded on blogs anywhere on the Web. These Analytics though, are part of your application itself. So you can track its usage outside of the original HTML page the previous iteration of Analytics would have restrained you to.

And it’s free! Check out the code repo.

Exactly how search engines deal with the content of Flash-based websites and information in SWF files has notoriously been a bit of a grey area for a long time. Historically, website creators had to battle with clients as to whether the aesthetic potential of Flash was enough a pay-off against their judgement of the importance of this new idea called ‘SEO’.

In July of last year, Adobe announced a collaboration with Google (1, 2) and Yahoo! to develop a new Flash Player technology specifically to enhance the search results of dynamic content in Flash – ultimately, to make the SWF searchable.

But it was unclear how it worked, what it actually did and what provisions the Flash developer or content creators would have to make.

Peter Elst aired his thoughts and agreed as I did, it looked like a ‘backup’ or intermediary solution. There also lacked a standard or recommended approach to deploying the content for this new technology – presuming this new platform hadn’t just become instantly intelligent to all possibly methods of delivery.

Adobe later published an FAQ, but still it wasn’t very technical, so a few developers started experimenting. After seeing Peter’s attempts, Ryan Stewart announced a Flex SEO Contest – an outright declaration that we’re confused but determined to find out what exposure our content has. As well as being a bit of fun. 😉

Dominic Gelineau constructed fourteen test cases, essentially finding every possible way you could contain a simple text string in a SWF file (see 1 – 7 here, 8 – 14 here). He used both static and dynamic TextFields, populated them in various ways, MXML components, standard Flash UI components, whether to use states, etc – covering all the bases across Flash and Flex.

Initially he concluded Google wasn’t really finding anything new, but in a later article for InsideRIA he listed his principle observations:

  1. Most of the content that was on the stage/timeline at compile time would be indexed even if it was outside the viewing area.
     
  2. The TextArea, Text, ViewStack and custom MXML component in Flex would get indexed if they were in the MXML (the Flex equivalent of being on the stage) but the Label component would not.
     
  3. Until October, SWF files embedded in the HTML using JavaScript (SWFObject, AC_RunActiveContent, etc) could not be found on Google.
     
  4. Again until October, anything related to the ActionScript 3 method addChild would not get indexed. As an example, adding a MovieClip from the library with static text in it using addChild method would not show up in Google’s search results. In the same way, using states in Flex wouldn’t work. My guess is that since states uses addChild in its MXML syntax, once compiled it would get converted to the addChild method in AS3.
     
  5. Finally, any content loaded externally from the embedded SWF file wouldn’t get indexed, but was clearly stated by Google.
     

Fortunately, Jim Corbett, Flash Player Engineer at Adobe offeres some much-need clarification, answering many of these questions at the Adobe MAX conference this year. The video can be found at Adobe TV, (I’m having problems embedding it with WordPress) – it’s lengthy, and gives a good insight into the Player’s search mechanics.

Last month’s Flash platform group meeting was presented by Michael Plank and Frank Piotraschke from Powerflasher, authors of FDT the Actionscript IDE plugin for Eclipse. One of many features of FDT Frank demonstrated was SWC and SWF(-ish) browsing support.

He opened debate as to whether adopting a SWC or SWF nominated workflow for handling compiled components and libraries is more desirable, presenting methodology for both. Although then a decent excuse for him to show off FDT, each approach has its benefits and it’s good to know how to code both – previously I’d never used SWFs in this way, always choosing SWC files.

To use a SWC as a linked library and access a clip as a dynamic class, establish a linkage in the library to a class definition that does not exist – for example:

com.hibbins.Clip

When you click the ‘Validate class definition’ tick, you’ll get an alert that the definition cannot be found and it will be automatically generated upon export. Export the SWC and add it to your project classpath and it’s ready to use. Just instantiate it as you would any other class, note the import if your packaging requires it:

package
{
import flash.display.Sprite;
import com.hibbins.Clip;

public class SwcTest extends Sprite
{
public function SwcTest()
{
var clip:Clip = new Clip();
addChild(clip);
}
}
}

To do the same with a library from a compiled SWF, you need to load the SWF file containing your assets into the same Application Domain as your loading SWF file. The following diagram represents the classes available to each SWF file considering their respective domains:

Application Domains

The SwfTest class exists within the loading SWF file, the Clip class in the library file (published as assets.swf). Loading the file in to the current Application Domain shared the loaded SWF domain classes within the main class pool:

Application Domains

The following code demonstrates how to do that, then instantiate the class with the getDefinitionByName method:

package com.hibbins
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.utils.getDefinitionByName;

public class SwfTest  extends Sprite
{
public function SwfTest()
{
var loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onLoadComplete);

loader.load(new URLRequest(“assets.swf”), context);
}

private function onLoadComplete(event:Event):void
{
var ClipClass:Class = getDefinitionByName(“com.hibbins.Clip”)
as Class;

var clip:MovieClip = new ClipClass();
addChild(clip);
}
}
}

Both are pretty quick ways to handle custom MovieClips from your library dynamically. If you want to add any functionality to the clips you can write their classes using matching definition paths. Be aware though, any timeline actions will be dropped if you do this.

If you really want to keep frame actions, I’ve found two ways – firstly by using frame labels which are maintained elsewhere and coding around those, the other only works with SWC files, creating a class which extends from the dynamic clip class. With the SWC in your class path you won’t have any compilation errors.

As Frank pointed out, SWC files can be a lot heavier when loaded on application startup which can make your main SWF quite large. Using SWF files over SWCs, you can create an sequential load manager or only load them asynchronously when necessary. Also, with SWCs being relatively new in comparison to SWF use, you might have no choice. On the other hand, the SWC workflow is simpler and many IDEs have some form of SWC explorer – FDT and Flex Builder, for example.

There’s also an a shortcut to display the contents of a SWF in the same way in FDT, though it’s undocumented. Hit Alt+Shift+W and you can get an outline view (I don’t think this works on all versions of FDT though). It would be good if when this is better integrated into FDT, the classes are recognised in a similar way to the SWC support for auto-completion – as Tink says in the video, to avoid the ‘flakey’ long line of code that’s easily prone to mistyping.

Presentation slides, source code and videos are now online [via].

Peter Elst recently posted the Sneak Peeks session from the Adobe MAX conference this year. It shows some really good projects, that as the disclaimer strongly advises, may or may not be featured in future releases of the various Creative Suite software:

Serge Jespers presented Nitro, a platform to design, build and distribute Flash widgets ‘on multiple screens’ – i.e. multiple target devices. Intended to create a coherent work flow and end-user deployment environment of ‘widgetized’ Flash content.

There’s a nice demo of pulling a widget directly from a browser to the desktop, detected by the central Nitro widget ‘dock’ which simultaneously synchronised to a mobile device and television. If it’s even half as simple as the demo suggested, then delivering widgets recognised as solid portable, ubiquitous single-purpose applications rather than kitschy or novelty desktop ‘toys’ could very soon be far easier realised.

Meer Meer is a virtual laboratory of browsers, basically a Flex app that runs a variety of coded browsers (of multiple operating systems) on a single server and centralised into a one application. Integrated directly into Dreamweaver, you can render all your local files in each browser with one click of a button. Not only does it offer split-screen views, but an onion skinning mode to overlay browser images without the need of endless screen grabbing (as I currently do) if you play to the pixel. This makes my browser testing posts (1, 2) completely useless, excellent. 🙂

If none of that interests you, just watch Rufus Deuchler presenting Shai Avidan’s Infinite Images and Infinite Panoramas – I won’t even try explaining – you need to just watch, starts around the 55 minute mark.

Also featured was RTMFP Application-level Multicasting, which broadcasts live video with P2P-style distribution methods; Durango, a Flex/AIR framework to easily create mashup applications almost code free; LiveCycle services in combination with CS4; and running server-side Actionscript seemingly without Flex or Flash – the demo didn’t really work out.

Can’t afford Flex Builder? Build your own!

Well, almost. You can get some easy auto-completion, syntax highlighting and simple error checking of MXML scripts with a nifty bit of XSD integration with Eclipse, using an XML Schema doc from an open source project, imaginatively titled XSD4MXML.

The XSD format is the typical extension for XML Schema, a document defining a set of rules to which an XML document must conform. Eclipse can utilise a Schema document then, in combination with some of the baked in plugins – namely Web Tools and the standard XML editor – to offer these benefits.

The XSD4MXML document outlines what properties any given tag can express – at the most basic level for example, an Application tag can have a layout attribute or a frameRate attribute, an HTTPService tag has a url attribute – but it references every attribute, includes inheritance, for all properties, events, methods etc. This document weighs in at 1.2mb, it’s almost 28,000 lines of code.

Combine that with the error checking the standard XML editor offers and the auto-completion when an XSD format is provided and very quickly you’ve got some useful functionality.

So it goes:

  1. Get the latest version of Web Tools. A fresh Eclipse build should come with it, otherwise follow the instructions here. NB: I’m using Europa, the update process is a little different for the new Ganymede release – also, don’t try and get the latest Web Tools version if you haven’t got Ganymede.
     
  2. Grab the latest version of the XSD4MXML doc.
     
  3. Open the Preferences panel in Eclipse, go to Web and XML > XML Catalog and select ‘User Specified Entries’.
     
  4. Click ‘Add…’ and browse to your local copy of XSD4MXML, the namespace should fill automatically when you’ve found it, click OK.
     
  5. Go to General > Editors > File Associations and add the *.mxml type. Under ‘Associated editors’ add the XML editor.
     
  6. Still in the preferences, go to Content Types, open the Text type and select XML, again add *.mxml.
     
  7. Create a new project and MXML file, add the XML header, an mx:Application tag and namespace:
     
  8. <?xml version=”1.0″ encoding=”UTF-8″?>
    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”&gt;

    </mx:Application>

  9. Within the Application tag, hit Ctrl+Space for the Content Assist menu and you should see a full list of MXML tags and you’re done.
     

You can use the Ctrl+Space shortcut for auto-complete on all tags, properties, events, etc. The XML editor should highlight syntax and do a little error checking itself.

Here’s a handy bit of code. Although every release of the Flash Player provides full backward compatibility in viewing published content, the introduction of ActionScript 3.0 and the new Actionscript Virtual Machine (AVM2) in Flash Player 9 presented some challenges for interoperability at author time, specifically switching between code and SWFs of the different Actionscript versions.

Combining Actionscript 3.0 code with previous language versions can’t be achieved as easily as the old school hacks of plugging together bits of Actionscript 2.0 or 1.0 wherever they fit  – but that’s half the intention, I’m sure.

It’s fully documented at Flash LiveDocs, but now, essentially:

  • A single SWF file cannot combine ActionScript 1.0 or 2.0 code with ActionScript 3.0 code.
  • ActionScript 3.0 code can load a SWF file written in ActionScript 1.0 or 2.0, but it cannot access its variables or functions.
  • SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0 (without a couple fiddly exceptions).
     

Generally, avoid it – it’s bad practice anyway. But if you have no other option – or, as I recently encountered (thus this post), your designer inevitably sends you an AS2 SWF for your AS3 project 😉 – you can use the LocalConnection class to create a simple interface between the two files that actually also gives you quite an amount of scope for interoperability as and when desired.

If you’ve not used it before, the LocalConnection class facilitates communication between LocalConnection objects instantiated within the same or multiple SWF files. With that ‘access’, you can invoke any amount of methods on connected clients as you can write. The communication exists within a specified domain and all clients must be on the same computer, but it’s not limited only to the Flash player. SWFs can communicate within a browser sandbox, or from browser to standalone SWF viewer, or to a projector etc etc – and anything in between.

For this example, we establish an AS3 SWF as our sending file, calling methods within an AS2 SWF receiving file, which handles the call and invokes the methods.

In the AS3 (sending) file:

var localConnection:LocalConnection = new LocalConnection();
localConnection.addEventListener(StatusEvent.STATUS, onStatus);
localConnection.send(“testConnection”, “connectionHandler”, “Boo.”);

function onStatus(event:StatusEvent):void {
switch (event.level) {
case “status” :
trace (“LocalConnection.send() succeeded”);
break;
case “error” :
trace (“LocalConnection.send() failed”);
break;
}
}

In the AS2 (receiving) file:

var localConnection:LocalConnection = new LocalConnection();
localConnection.connect(“testConnection”);

localConnection.connectionHandler = function(string:String):Void {
trace (“Message from AS3 SWF: ” + string);
}

Easy peasy. You can send any amount of arguments and call any method on the listening SWF – so long as there’s a handler to deal with it.