Category: Flex

  • There is Nothing Wrong with Learning AS3

    I’m writing this post out of guilt. I’m working with a contractor today, Charles Schulze, helping him get a working version of one of our API’s. He’s been really patient with us while we get a working build to him that he can build around. We’re all in this walled off area of desks and tables called “The Pit”. It makes it easier to collaborate compared to f’ing cubes. A discussion was going on about AS2 and AS3 differences. Charlie again mentions he wants to get more projects doing AS3. He doesn’t get as many as AS2. I told him if he is doing pure ActionScript 3 all the time, he should be doing Flex work instead of Flash. He laughed.

    “Dude, you’re using classes in ActionScript 2… you’re building a mini-app. If you know ActionScript 3, you’re practically an application developer.”

    He then looked upset. He didn’t show it, but I could see it. He brought up various scenarios, so I did my pitch on what I think Flex is for and what Flash is for (typically). I threw in the caveat it’s not always that black and white, especially with hybrids like him who can design and code equally well. If you are in a particular industry, it makes it easier to focus on a skill set. For example, if you keep hanging around the agency world doing contract, you’re more app to get bling using your Flash skills. While I’m sure they’d ask for AS3, a lot of OOP and design patterns are useless when you have a week to get stuff done that would take me 2 months. Vice-versa in the software world in using Flex. A lot of the design appreciation just isn’t there, and you cannot use a lot of the skillsets that don’t apply to coding.

    He brings up more postulate scenarios, such as doing interactive, design-driven websites. As if on cue, Nick throws in the “doing 3D interface work”. Yeah, I was owned… but I still didn’t think that was justification for putting AS3 in a product meant to encourage upgrades, which then encourages stock holders to see post-merger success, and thusly purchase more stock in Adobe. I look at Flash 8 and go, “Damn, they got that one soooo right. Phat design additions and re-implementation of Script Asisst. Macromedia for the win!”.

    He then mentions quietly with a resolute sadness, head down working on his computer, that I made him not as motivated to learn more AS3 than he already knows. I immediately felt bad, like I had erred in communicating and then spent the next 5 minutes un-doing… or rather, re-directing my rallying towards learning AS3 in Flash CS3, not Flex Builder. Sapping passion from another is a major sin.

    I explained the immediate benefit of runtime errors. Yes, that dialogue box in your face can belt your self-esteem at times, but nothings more frustrating than an error that just stealthily never appears. Now, you see them when your SWF is running, AND can see the path leading up to their cause of failure. Furthermore, you’ll never have that nagging feeling of “maybe I should optimize my code…”. AS3, when used even with an once of effort towards using strong typing gives you mad speed increases. This won’t necessarily improve your animation speed, but certainly won’t detract from it, especially in games, or complicated menu systems. The days of seeing “Why does ‘parseXML’ freeze my animation?” on mailing lists should be a thing of the past. E4X is slower than DOM (aka XML.childNodes ) … but typically uses less code. Finally, the increased cleanliness of the strong-typing implementation will ensure your code probably works right when you compile, better than AS2. This confidence makes you a better Flash Developer.

    Let’s not forget the most important… file size. Flex 2 SWF with a Button component, 126k. Flash CS3 SWF with a Button component, 15k. That assumes your even using the new CS3 components; one you could could be smaller for example. Both Flash CS3 & Flex 2 produced Flash Player 9 AS3 SWF’s run the same speed: fast as nuts.

    So, I hope I got Charlie psyched again about getting more AS3 projects. I felt like a dick stealing his joy on wanting to get more into it, and felt I made a valid, applicable case to him to get him back in the mood for it. Hopefully my frustrations at feature choices won’t detract you either. You can learn AS3, reap the rewards, and steer clear of all the OOP & design patterns if you so choose. AS3 alone is still pimptastic in Flash CS3. There is nothing wrong with learning AS3. Just remember AS1 and AS2 are still powerful and a valid part of your arsenal.

  • Flash Content in Flex Preso

    I did a Connect presentation for the Arizona Flash Platform User Group Wednesday evening about using Flash content in Flex. If you didn’t get to attend my 360Flex presentation in San Jose, California back in March, this is a lot of what I covered there. I’ve added some updates based on my 4 months of working. I didn’t get to talk about the Flex component kit for Flash as in depth as I wanted because my copy of Flash CS3 is giving me grief on my PC with licensing. It’s about 1 hour and 20 minutes long and you can skip ahead through the stuff you already know.

    Flash Content in Flex

  • Making a Cooler Preloader in Flex: Part 1 of 3

    Preloader Preview

    Preface

    Preloaders in Flex are not like preloaders in Flash. Gone are the days of the 1 liner:

    if ( _framesloaded < _totalframes ) gotoAndPlay ( 1 );

    We now have base classes and setter properties. While you may have to write a class and then set that class on your Application’s preloader property, it’s really pretty easy once you do it more than once. This tutorial will show you how to build a preloader in Flex using a Flash built animation.

    Introduction

    Flex’ built in preloader is pretty sweet. It auto-adjusts for your application’s color to stand out, it handles all aspects of preloading. This includes remote shared libraries, fonts, and even deferred classes used in modules. Finally, it deals with the initialization of your Flex application which can possibly take longer than a few milliseconds.

    If you are building branded applications, every little detail counts in enforcing your brand identity upon your user. You want to remind them the positive experience they are having was brought to them by you. Nothing is more important than a first impression, and the first thing people see in a Flex application is the preloader. It is important that you spend adequate time on making it look good and consistent.

    To make a custom preloader for Flex, you have to do 2 steps:

    1. Write a class that extends DownloadProgressBar
    2. Set the preloader property on your Application class to your preloader class.

    No witty 3 step process here.

    The purpose of extending DownloadProgressBar is to handle the various things that happen in the life cycle of preloading (yes, we have life cycles now, not just downloading of bits). You do not have to handle anything save the FlexEvent.INIT_COMPLETE. You could for example put some dots who are ridin’ spinnaz and that’s your preloader.

    …or, you could handle all events, and duplicate the Flex one with a different design showing the download & initialization progress.

    The steps for making a custom Flash Preloader for your Flex app are as follows:

    1. Make a 100 frame MovieClip. TextField optional (as is everything).
    2. Give MovieClip linkage ID with no class name.
    3. Compile your SWF (“Test Movie”)
    4. Write your own Preloader class in Flex Builder which uses your Flash MovieClip.
    5. Set the Appliction.mxml preloader property to your custom class.

    Making Your Flash Symbol

    In Flash, you make a MovieClip that is 100 frames long. This will be the preloading part of your preloader, the MovieClip that shows the progress of the SWF downloading. Notice I have both a 100 frame animation as well as a dynamic TextField. The TextField will have the percentage numbers (i.e. “73%”) put into it dynamically.

    Notice, also that the TextField has an instance name. This is so I can target it with code. Keep in mind, even though we are giving the TextField an instance name, we’ll be targeting it with code in Flex. We won’t be writing any code in Flash.

    Finally, I wrap my preloader in a MovieClip because I want the preloader to fade out when it’s done.

    I make sure to give the preloader an instance name so I can “dot dot down” to the preloader through the animation. Dot dot down is Flash slang for using dot syntax to walk down the display tree to target a MovieClip you want to interact with via code. In our case, it could be:

    _root.my_clip.preloader.amount_txt.text = "70%";

    Omg, I used _root, lol, l@mz03, me fired.

    Finally, you export your Symbol with a linkage ID. Exporting as Flash 8, AS2, you just fill in the linkage ID class. Don’t export as Flash 9, AS3. If we did that, we might as well write the class for the preloader , and that’s just too much work, and too much added file-size for a class that’s supposed to be simple and most of all lightweight. If you are using Flash CS3, just change your publish settings to Flash 8, AS2 or AS1.

    Flex will look for this linkage ID name when you are embedding the MovieClip. Now compile your SWF and your done.

    Custom Preloader Class

    You then write your own Preloader class. Have it extend mx.preloaders.DownloadProgressBar. There are multiple ways to embed Flash content. For our purposes, we’ll embed to a class property.

    If you look at the Preloader’s setter function, you’ll see we get a Sprite (1 frame MovieClip) that emits all the preloading events we’ll care about. In this case download progress, when the SWF has finished downloading, when the SWF starts to initialize classes, and when initialization is complete.

    Our download progress & SWF download done functions will dig down into the Flash MovieClip, and show download progress in both the text field, as well as making the preload MovieClip symbol animate via gotoAndStop based on the download percentage. Since download percentages are 100%, it makes it pretty easy to figure out what frame to go to.

    The initialization ones just show “Initializing…” in the TextField.

    Unlike most Flex preloaders, we want ours to animate when done, and only THEN actually launch into our Flex application. You can accomplish this by not dispatching the complete event. Dispatching this let’s the Flex application know the preloader is done. In our case, we want to wait till the Flash animation is done before doing so. We add a framescript ( a function called when the Playhead reaches a frame) to frame 21. When the animation is done, it’ll hit this frame, call our preloader class’ function. This will stop the animation and dispatch the event, letting the Flex application know we’re ready.

    Conclusion

    That’s it! Keep in mind it’s hard to test these things locally on your box. In Flash, we have the bandwidth profiler, but there is no such thing in Flex. You can either use network throttlers, like Charles. Alternatively you can upload the files to your site, install the Firefox Web Developer Toolbar, and choose disable cache.

    In the next part, we’ll be taking advantage of Flex as a statefull client, and getting all the data you need. This takes time, so we need a cool way to show this to user as well as making it fail gracefully.

    Flash Preloader in FlexExample | Source | ZIP

  • Video Ad SDK’s?

    Ooooook, a big wtf yet again. Was on-site with a client today gathering requirements for a video player. While we provide a wide-variety of players, the ad integration I was educated on in-meeting. Apparently before I got on board, the Flash Engineers before me had gotten bloody noses learning about and implementing an in-player solution for ads for Flash via Lightingcast.

    To give context, there is 3 main points people who have video content they wish to put online with an ad supported model care about:

    1. ad relevant to the video
    2. ad only shown for some videos
    3. metrics on both ad & player

    With Google Ads and text content, this stuff is easy. You copy and paste your Google Ads on a page, and it does it’s thing. You can even define channels to help organize your aggregated ad data, and block specific areas, whether by blocking specific competitors or by simply not including code in your client pages.

    Video, not so much. First, video has no context. It’s a binary block of data, and a lot of it. I’ve read sparse blog entries over the past few years discussing various companies using various technologies to get better context on video. They are doing some similar things with images and audio as well. There are 2 approaches to this. The first involves using various algorithms to gain context from the data. For example, a lot of camera’s have technology that can identify a face in the picture. This helps a lot with auto focus. Similar technology with video is used today in stores to identify customers who are “confused” and thus need an on the floor employee to help them find what they are looking for (say Best Buy). They do this by the video camera’s reading the customer’s posture in the aisles. This technology can be used by advertising companies in a latent form to gain context from a video and deliver more relevant ads without the help from text on the page surrounding the video as a context-crutch.

    The second way is user-organized content in the form of user created metadata and “tags”. Assuming this data is in fact valid, you gain not just qualitative data about a video which is much more valuable to serving ads than the quantitative “it’s a video with a car in it”. The added benefit is that you gain the different perceptions of the video’s type. People tag videos in different ways. This combination of data is powerful.

    That’s how you get relevant ads for video now and it’ll improve in the future. The “show some ads for only some videos” is usually handled via the CMS in charge of displaying the content on the webpage. The metrics depend on which player you are using and which ad service you are using, and at what degree.

    What boggles my mind is that I’ve been told there are NO API or SDK’s out there. I’m awaiting an email from a co-worker about info that is under NDA from some unnamed company that may have an API that he’s already seen. Apparently they had an SDK available for client, in browser technologies, but it didn’t have docs explaining how to get the ads according to my co-worker. Bottom line, most people currently use Google Ads next to their Flex apps, or for players rely on surrounding HTML content. For pre-roll / mid / post-roll video ads, that’s an f’ing joke. Furthermore, the ad companies (Doubleclick Motif, Eyespot , etc.) nickle and dime you to death on even getting metrics. You could build your own player obviously to capture your own metrics, but then said player isn’t integrated with their ad data. Chicken and egg problem.

    I bitched at Ted Patrick from Adobe over dinner when I was in San Fran about metrics, but I think now it’s at about the same level of market need as SCORM and other LMS integration is. Most people just use the lame ass API’s that make no sense, are all different, and code their own bridge in Flash / Flex to talk to these weird JavaScript API’s. Ted was like, “Well, if you want to build your own, just add an event listener to SystemManager in Flex with an uber high priority”. Paraphrasing, but good idea.

    Anyway, anyone know of an ad service that allows you to integrate ads with Flash / Flex through an API, including videos? Furthermore, this ad data can be controlled just like most ads can via targeted categories and content? Icing would be we could associate said data with our own metrics, even if it required custom coding. Till then, I’m awaiting this SDK email from co-worker, hoping it’s been improved since he originally saw it…