FORUMS: list search recent posts

YouTube Annotations in Flash

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Will Lyons
YouTube Annotations in Flash
on Dec 1, 2009 at 5:24:26 pm

I want to be able to create custom videos similar to youtube annotations, where a short video plays and at the end the viewer is presented with several options of how the video can continue. I'm thinking the way to go is using action script, and just add an event listener to listen for the end of the video, and present buttons upon the video's completion. It seems simple, but my question is how can I create this short piece of code, and have it plug in multiple videos. For example, after the user selects the way they want scene 1 to end, how can I load the videos for scene 2 using the same code, rather than having a huge long list of code for each 'scene. Would I use an array and some how have the code move through the array. Perhaps I should set up an array for each 'scene'? I'm new to flash and hacking through this, so I would really appreciate any help from all the knowledgeable minds here on the COW!
Cheers,
Will Lyons
Penstock Productions


Return to posts index

Marcus Geduld
Re: YouTube Annotations in Flash
on Dec 1, 2009 at 10:27:40 pm

One way to do it is with a Dictionary, which is a new structure available in AS 3.0. It's similar to an Array, but it allows you to associate objects (e.g. buttons or movieclips with data).

import flash.utils.Dictionary;

//let's say I have three buttons, btnGoogle, btnYahoo, and btnCow

var sites : Dictionary = new Dictionary();
sites[ bntGoogle ] = "http://www.google.com";
sites[ btnYahoo ] = "http://www.yahoo.com";
sites[ btnCow ] = "http://www.creativecow.net";

Notice that I did NOT place quotation marks around the button names inside the brackets. It's NOT sites[ "btnGoogle" ]...

Then I'd link all my buttons to a click handler:

//in the line below, change MovieClip to Button
//or whatever you've used
for ( var key : MovieClip in sites )
key.addEventListener( MouseEvent.CLICK, clickHandler );

Here's the handler function:

function clickHandler( event : MouseEvent ) : void
{
var target : MovieClip = event.currentTarget as MovieClip;
var site : String = sites[ target ];
navigateToURL( site );
}

In your app, you'd store urls of videos instead of websites, and instead of the navigateToURL method, you'd use FLVPlayback.play().


All of the above is the hacky way to do it. The more robust method is to use an Object-oriented approach. If I haven't lost people already, I'm sure I'll do so now. But as you learn more about AS, try to pick up some knowledge about OOP (Object Oriented Programming). Your apps will be much easier to maintain!

I'd create a new type of object: A type of button or movieclip that can store the url of an associted FLV:

package
{
import flash.display.SimpleButton;

class FLVButton extends SimpleButton
{
public var flvUrl : String;
}
}

Then I'd use this instead of regular buttons.

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index

Adam Ashby
Re: YouTube Annotations in Flash
on Dec 2, 2009 at 12:26:17 am

Marcus,

Do you have any recommendations for resources (sites, books, etc.) to help one wrap their head around OOP using AS3?

Thanks,
Adam


Return to posts index


Marcus Geduld
Re: YouTube Annotations in Flash
on Dec 2, 2009 at 12:38:56 am

I really like the Foundation series from friendsofed.com:

http://www.amazon.com/Foundation-ActionScript-3-0-Flash-Flex/dp/1590598156/...

If you really want to put yourself through a course (and come out an expert at the other end), read that first. The the following in the order I've listed.

- Essential Actionscript 3.0. There will be some overlap with the Foundation book, but that's good. It's worthwhile going over this stuff more than once.
http://www.amazon.com/Essential-ActionScript-3-0-Colin-Moock/dp/0596526946/...

- AS 3.0 Design Patters: http://www.amazon.com/ActionScript-3-0-Design-Patterns-Programming/dp/05965...

- Advanced ActionScript 3 with Design Patterns: http://www.amazon.com/Advanced-ActionScript-3-Design-Patterns/dp/0321426568...

- Clean Code (not AS, but every programmer should read it when they get past all the preliminary stuff outline in the above books):
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350...

If you prefer video, try some of the AS titles on lynda.com and/or this DVD set: http://www.amazon.com/Colin-Moocks-ActionScript-Weekend-Course/dp/059680157...



Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index

Adam Ashby
Re: YouTube Annotations in Flash
on Dec 2, 2009 at 1:05:55 am

Great! Thanks.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]