Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Sample Code: Using the API with AS3
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 29 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Matthew  
View profile  
(3 users)  More options Mar 17 2008, 12:07 pm
From: Matthew <matthew.enci...@gmail.com>
Date: Mon, 17 Mar 2008 09:07:09 -0700 (PDT)
Local: Mon, Mar 17 2008 12:07 pm
Subject: Sample Code: Using the API with AS3
You will need to create an AS2 file that accesses the API.
Then you need to make a connection to that file using a
LoacalConnection.

The following the the code needed for both these files:

AS2:

System.security.allowDomain('www.youtube.com');
System.security.allowDomain('gdata.youtube.com');
System.security.allowInsecureDomain('gdata.youtube.com');
System.security.allowInsecureDomain('www.youtube.com');

var loadInterval:Number;
var ytplayer:MovieClip = this.createEmptyMovieClip("ytplayer",
this.getNextHighestDepth());
var dev_key:String = "YOUR_KEY_HERE";
var swf:String = "http://gdata.youtube.com/apiplayer?key="+dev_key;

//This created a connection for AS3 to talk to it
var _as3_to_as2:LocalConnection = new LocalConnection();
_as3_to_as2.connect("AS3_to_AS2");

//This is to connect to a connection started by the AS3 file
var _as2_to_as3:LocalConnection = new LocalConnection();

ytPlayerLoaderListener = {};
ytPlayerLoaderListener.onLoadInit = function() {
    loadInterval = setInterval(checkPlayerLoaded, 250);

}

function checkPlayerLoaded():Void {
    if (ytplayer.isPlayerLoaded()) {
                //Let the AS3 file know that the player is loaded
                // the function onSwfLoadComplete exists within the
AS3 file
                _as2_to_as3.send("AS2_to_AS3", "onSwfLoadComplete");

                clearInterval(loadInterval); // IMPORTANT - kill the interval

                ytplayer.addEventListener("onStateChange", onPlayerStateChange);
                ytplayer.addEventListener("onError", onPlayerError);
                loadIndicator._visible = false;

                ytplayer.setSize(250, 206);
                ytplayer.loadVideoById("fKQAaPDshbc", 0);
        }

}

function onPlayerStateChange(newState:Number) {
     //do something when player changes state

}

function onPlayerError(errorCode:Number) {
    //do something on player error

}

var ytPlayerLoader:MovieClipLoader = new MovieClipLoader();
ytPlayerLoader.addListener(ytPlayerLoaderListener);
ytPlayerLoader.loadClip(swf, ytplayer);

//////// CREATE EVENT HANDLERS
// These functions can be called from within the AS3 file
// This is the window where AS3 will access the API
// You can add any of the Javascript Api here

_as3_to_as2.pauseVideo = function(){
    ytplayer.pauseVideo();

};

_as3_to_as2.playVideo = function(){
    ytplayer.playVideo();

};

_as3_to_as2.stopVideo = function(){
    ytplayer.stopVideo();

};

_as3_to_as2.loadVideoById = function(id){
        ytplayer.loadVideoById(id, 0);

};

AS3

package com.yourcompany.services{

        import flash.system.Security;
        import flash.display.Sprite;
        import flash.display.Loader;
        import flash.net.URLRequest;
        import flash.events.StatusEvent;
        import flash.net.LocalConnection;

        public class YouTube extends Sprite{
                private var _loader:Loader;
                private var _as3_to_as2:LocalConnection;
                private var _as2_to_as3:LocalConnection;

                public function YouTube(){
                        init();
                }

                public function init(){
                        Security.allowDomain('www.youtube.com');
                        Security.allowDomain('gdata.youtube.com');
                        Security.allowInsecureDomain('gdata.youtube.com');
                        Security.allowInsecureDomain('www.youtube.com');

                        _as3_to_as2 = new LocalConnection();
                        _as3_to_as2.addEventListener(StatusEvent.STATUS,
onLocalConnectionStatusChange);

                        _as2_to_as3 = new LocalConnection();
                        _as2_to_as3.addEventListener(StatusEvent.STATUS,
onLocalConnectionStatusChange);
                        _as2_to_as3.client = this; //This enables the local connection to
use functions of this class
                        _as2_to_as3.connect("AS2_to_AS3");

                        _loader = new Loader();

                        _loader.load(new URLRequest("yt.swf"));
                }

                private function stopVideo() {
                        _wui_to_ytl.send("AS3_to_AS2", "stopVideo");
                }

                private function playVideo() {
                        _wui_to_ytl.send("AS3_to_AS2", "playVideo");
                }

                private function pauseVideo() {
                        _wui_to_ytl.send("AS3_to_AS2", "pauseVideo");
                }

                public function loadVideoById(id) {
                        _wui_to_ytl.send("AS3_to_AS2", "loadVideoById", id);
                }

                public function onSwfLoadComplete(){
                        addChild(_loader);
                }

                private function onLocalConnectionStatusChange(e:StatusEvent):void{
                        // error was thrown without this handler
                }
        }

}

--------------------------------------------------------------------------- -----------------

To use this code (AS3):

//Make this your document class

package{

        import flash.display.Sprite;
        import com.yourcompany.services.*;

        public class Main extends Sprite{
                private var _youtube:YouTube;

                public function Main(){
                        init();
                }

                public function init(){
                        _youtube = new YouTube();
                        addChild(_youtube);

                        _youtube.loadVideoById("hutaAnfk2RE");
                }
        }

}

--------------------------------------------------------------------------- ----------------------------------------

I changed some of this code here in the editor i hope i did not break
anything. Let me know if it works.

You can build controls for the player right in the as 2 file...... or
in the as 3 file via the functions built off of the local connection.

Hope this helps,

Matthew


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Fisher  
View profile  
 More options Mar 17 2008, 5:51 pm
From: Jeff Fisher <jfis...@youtube.com>
Date: Mon, 17 Mar 2008 14:51:26 -0700 (PDT)
Local: Mon, Mar 17 2008 5:51 pm
Subject: Re: Sample Code: Using the API with AS3
Hi Matthew,

Thanks for contributing this! If you'd like to do a blog post or
something we can link to, we'd be happy to feature your work to a
wider audience. :)

Cheers,
-Jeff

On Mar 17, 9:07 am, Matthew <matthew.enci...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthew  
View profile  
 More options Mar 17 2008, 6:31 pm
From: Matthew <matthew.enci...@gmail.com>
Date: Mon, 17 Mar 2008 15:31:05 -0700 (PDT)
Local: Mon, Mar 17 2008 6:31 pm
Subject: Re: Sample Code: Using the API with AS3
Ok i will do a post about it later and send you the link.

Matthew

On Mar 17, 5:51 pm, Jeff Fisher <jfis...@youtube.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jassa  
View profile  
 More options Mar 26 2008, 2:47 am
From: jassa <ja...@viamedia.com.au>
Date: Tue, 25 Mar 2008 23:47:47 -0700 (PDT)
Local: Wed, Mar 26 2008 2:47 am
Subject: Re: Sample Code: Using the API with AS3
Hi Matthew - thanks for sharing! I've had a play around with it and
it's great. Just one question: I'm getting a "Access of undefined
property _wui_to_ytl" error in the loadVideoById function (in the
YouTube class). Any idea why this may be happening? It's been a long
day and I've only just had time to play with this so forgive me if
I've missed something obvious ;)

Cheers,
Jassa

On Mar 18, 8:31 am, Matthew <matthew.enci...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
benjaminruehl@googlemail. com  
View profile  
 More options Mar 27 2008, 6:33 am
From: "benjaminru...@googlemail.com" <benjaminru...@googlemail.com>
Date: Thu, 27 Mar 2008 03:33:13 -0700 (PDT)
Local: Thurs, Mar 27 2008 6:33 am
Subject: Re: Sample Code: Using the API with AS3
I have the same problem. Do you know the solution?

On 26 Mrz., 07:47, jassa <ja...@viamedia.com.au> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jassa  
View profile  
 More options Mar 27 2008, 8:50 am
From: jassa <ja...@viamedia.com.au>
Date: Thu, 27 Mar 2008 05:50:45 -0700 (PDT)
Local: Thurs, Mar 27 2008 8:50 am
Subject: Re: Sample Code: Using the API with AS3
Not yet - I'm hoping some one can help us out, or point us in the
right direction.

Let me know if you figure it out!

Cheers,
Jassa

On Mar 27, 8:33 pm, "benjaminru...@googlemail.com"


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthew  
View profile  
 More options Mar 27 2008, 11:20 am
From: Matthew <matthew.enci...@gmail.com>
Date: Thu, 27 Mar 2008 08:20:49 -0700 (PDT)
Local: Thurs, Mar 27 2008 11:20 am
Subject: Re: Sample Code: Using the API with AS3
I am sorry guys...i edited this on the fly i expected there to be an
error somewhere.

That variable should be _as3_to_as2 instead of _wui_to_ytl.

That should fix that porblem. I forgot to change that variable name.

Sorry about that.

Matthew

On Mar 27, 8:50 am, jassa <ja...@viamedia.com.au> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
benjaminruehl@googlemail. com  
View profile  
 More options Mar 27 2008, 11:34 am
From: "benjaminru...@googlemail.com" <benjaminru...@googlemail.com>
Date: Thu, 27 Mar 2008 08:34:47 -0700 (PDT)
Local: Thurs, Mar 27 2008 11:34 am
Subject: Re: Sample Code: Using the API with AS3
Nice and thanks.

I have another problem: What kind of url does the loaderobject need? I
tried it with "http://gdata.youtube.com/apiplayer?key="+dev_key but
the EventListener throws an error about the LocalConnection
([StatusEvent type="status" bubbles=false cancelable=false
eventPhase=2 code=null level="error"]).
Any idea to fix the problem?

thanks again

On 27 Mrz., 16:20, Matthew <matthew.enci...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthew  
View profile  
 More options Mar 27 2008, 1:29 pm
From: Matthew <matthew.enci...@gmail.com>
Date: Thu, 27 Mar 2008 10:29:13 -0700 (PDT)
Local: Thurs, Mar 27 2008 1:29 pm
Subject: Re: Sample Code: Using the API with AS3
I am not sure if i understand your question.

Matthew

On Mar 27, 11:34 am, "benjaminru...@googlemail.com"


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jassa  
View profile  
 More options Mar 27 2008, 10:25 pm
From: jassa <ja...@jossmedia.com.au>
Date: Thu, 27 Mar 2008 19:25:22 -0700 (PDT)
Local: Thurs, Mar 27 2008 10:25 pm
Subject: Re: Sample Code: Using the API with AS3
Thanks for that Matthew ;)

I can get it to run now but I'm getting a new error:
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

Any ideas?

Thanks,
Jassa

On Mar 28, 3:29 am, Matthew <matthew.enci...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
alejandro52  
View profile  
 More options Mar 28 2008, 8:48 am
From: alejandro52 <alexkaiserli...@gmail.com>
Date: Fri, 28 Mar 2008 05:48:51 -0700 (PDT)
Local: Fri, Mar 28 2008 8:48 am
Subject: Re: Sample Code: Using the API with AS3
I get the same error. This is dispatched when YouTube.loadVideoById is
called.It seems like the id variable is wrong or something.

On Mar 28, 4:25 am, jassa <ja...@jossmedia.com.au> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
oraboy  
View profile  
 More options Mar 28 2008, 1:19 pm
From: oraboy <ora...@gmail.com>
Date: Fri, 28 Mar 2008 10:19:01 -0700 (PDT)
Local: Fri, Mar 28 2008 1:19 pm
Subject: Re: Sample Code: Using the API with AS3
Matthew,

Thanks so much for this... great work and much appreciated!

One small comment:
In your example you call loadVideoById() on the AS3 YouTube wrapper
class immediately after creating it in the init() function. This
doesn't always work (as the AS2 counterpart may not have loaded yet).
It's best to start invoking methods only after the onSwfLoadComplete()
is triggered.

Not sure, but this might be the problem some people mentioned on this
thread previously...

On Mar 27, 10:29 am, Matthew <matthew.enci...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Amitt Mahajan  
View profile  
(2 users)  More options Mar 28 2008, 4:27 pm
From: Amitt Mahajan <amitt.maha...@gmail.com>
Date: Fri, 28 Mar 2008 13:27:45 -0700 (PDT)
Local: Fri, Mar 28 2008 4:27 pm
Subject: Re: Sample Code: Using the API with AS3
I went ahead and created a Actionscript 2 FLA wrapper using parts of
the code above as a basis.
http://static.myminilife.com/misc/ytas2toas3.fla

You should just be able to compile that as a flash8 swf and itll be
good for loading in flex.  I may be able to post the AS3 side of
things later if i get a chance(its heavily tailored to our specific
application right now).

Couple caveats:
1) You need to define your dev key.  It can be defined as a url param
or in the code itself.
2) Make sure to call stopVideo() and disconnect() from AS3 once you're
done with the wrapper swf.  This will let AS2 disconnect from AS3 to
let AS3 garbage collect the swf.  I was having issues with AS3 not
being able to play more than 1 movie if the SWF file needed to be
reloaded.  So if you see that problem, call disconnect over the
localconnection.
3) The funcs that return values, (getTotalBytesLoaded, getVolume,
etc..) currently don't report their results to AS3.  I'm not too
familiar with how local connection works.  So if someone knows how to
get the return data from localconnection function calls, please let me
know :)

On Mar 28, 10:19 am, oraboy <ora...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Amitt Mahajan  
View profile  
 More options Mar 28 2008, 4:40 pm
From: Amitt Mahajan <amitt.maha...@gmail.com>
Date: Fri, 28 Mar 2008 13:40:55 -0700 (PDT)
Local: Fri, Mar 28 2008 4:40 pm
Subject: Re: Sample Code: Using the API with AS3
Sorry one last thing, your actionscript 3 code needs to have the
following functions defined (in addition to the stuff Matthew said
above):
                /** Callback for when the player has finished loading. */
                public function onSwfLoadComplete():void {
                        /*  - This is what we're doing once the chromeless player has been
loaded.  the m_ytWrapper var is just an instance of the wrapper swf in
flex.
if(m_ytWrapper != null) {
                                addChild(m_ytWrapper);
                                loadVideoById(m_videoId);
                        }
                        */
                }

                /** Callback for the YouTube player status change */
                public function onPlayerStateChange(newState:Number):void{
                        // Do some stuff in response to player state changes
                }

                /** Callback for when an error has occured with the YouTube player.
*/
                public function onPlayerError(errorCode:Number):void{
                        // Handle errors, according to Geoff the errorCode is always 100
right now.
                }

On Mar 28, 1:27 pm, Amitt Mahajan <amitt.maha...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthew  
View profile  
 More options Mar 30 2008, 8:42 pm
From: Matthew <matthew.enci...@gmail.com>
Date: Sun, 30 Mar 2008 17:42:21 -0700 (PDT)
Local: Sun, Mar 30 2008 8:42 pm
Subject: Re: Sample Code: Using the API with AS3
Hey Amitt,

I took a look at the fla and it looks good... great job. I wish i had
more time to give away something as complete as what you did.

There is one other caveat that i should mention and it comes from
using the local connection. It seems that you can only make ONE
connection to a movie at a time using a particular id. In our case we
are using "AS3_to_AS2" like this:

      _as3_to_as2.connect("AS3_to_AS2");

This means that when you finally create your application and run it in
the broswer it will only work in the first instance i.e the first
browser window opened. All other windows opened after that, that uses
the same fla file will fail to work

To get around this i created a connection manager that gives the as 2
and as 3 files unique keys for every session opened. This means that
there will have to be a connection open in the as2 file that simply
receives the keys and then is closed.

If i have time in the coming week i will try to put my code in the fla
you created and release it on my website. Unless you want to make that
addition which seems very important.

Matthew

On Mar 28, 4:40 pm, Amitt Mahajan <amitt.maha...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dexterpg  
View profile  
 More options Apr 3 2008, 2:57 pm
From: dexterpg <alexkristianw...@gmail.com>
Date: Thu, 3 Apr 2008 11:57:39 -0700 (PDT)
Local: Thurs, Apr 3 2008 2:57 pm
Subject: Re: Sample Code: Using the API with AS3
Hello,

I'm trying to embed a youtube player into an existing flex
application.  I've only learned AS3, so some of this discussion about
AS2 is going over my head.  I think that this fla file that Ammitt so
kindly put together could be really helpful for me, but I don't know
how to use it.

Can someone please explain what I do with the fla file or the AS2
code?  Can I just put it into an '.as' file?  Thank you very kindly.

-dexter

On Mar 30, 5:42 pm, Matthew <matthew.enci...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
oraboy  
View profile  
 More options Apr 7 2008, 1:23 pm
From: oraboy <ora...@gmail.com>
Date: Mon, 7 Apr 2008 10:23:38 -0700 (PDT)
Local: Mon, Apr 7 2008 1:23 pm
Subject: Re: Sample Code: Using the API with AS3
dexter,

You need to compile the AS2 code using Flash Creative Suite (CS)...
Load CS, open the file, then Publish it (through the file menu). That
should generate an .swf file... put that file on the web-server where
your Flex application is and follow the instructions on that side.

BTW: If you are trying to embed the player in a Flex component, you
should inherit from UIComponent rather than Sprite

On Apr 3, 11:57 am, dexterpg <alexkristianw...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MoebiuZ  
View profile  
 More options Apr 28 2008, 6:21 pm
From: MoebiuZ <moede...@gmail.com>
Date: Mon, 28 Apr 2008 15:21:35 -0700 (PDT)
Local: Mon, Apr 28 2008 6:21 pm
Subject: Re: Sample Code: Using the API with AS3
Matthew,

I did a "connection manager" in the way you suggested. Something like
this:

AS2:

var randy:String = Math.random(9999).toString();

var _as2_to_as3:LocalConnection = new LocalConnection();
var _as3_to_as2:LocalConnection = new LocalConnection();
_as3_to_as2.connect("AS3_to_AS2" + randy);
_as2_to_as3.send("AS2_to_AS3", "clave", randy);

AS3:

public function clave(randy:String):void {
      keystring = randy;
     _as2_to_as3.close();
    _as2_to_as3.connect("AS2_TO_AS3" + keystring);

}

Basically interchanging a "key" to instance local connections. It
works fine (I can load more than one YouTube() instances on the same
swf), but only works loading the different instances in chain: When
the first instance loaded, then can load the second (I did it
assigning a mouse listener to create new instances with each click).

If I do:

  _youtube1 = new YouTube("fKQAaPDshbc");
  addChild(_youtube1);
  _youtube2 = new YouTube("fKQAaPDshbc");
  addChild(_youtube2);

I get the "already connected" error, because the first instance didn't
loaded yet when I call the second.

Can you avoid that with your connection manager without doing a chain
loader?

On 31 mar, 02:42, Matthew <matthew.enci...@gmail.com> wrote:

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Advent Media  
View profile  
 More options May 6 2008, 4:27 pm
From: Advent Media <and...@adventmedia.net>
Date: Tue, 6 May 2008 13:27:56 -0700 (PDT)
Local: Tues, May 6 2008 4:27 pm
Subject: Re: Sample Code: Using the API with AS3
The ASBridge components from jumpeyecomponents (http://
www.jumpeyecomponents.com/Flash-Components/Various/ActionScript-Bridg...)
handles the local connection functions to bridge between AS2 and AS3 -
it's currently free (0.9 beta).

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeffwinkworth  
View profile  
 More options Jun 3 2008, 10:14 am
From: jeffwinkworth <jwinkwo...@tvo.org>
Date: Tue, 3 Jun 2008 07:14:42 -0700 (PDT)
Local: Tues, Jun 3 2008 10:14 am
Subject: Re: Sample Code: Using the API with AS3
This is all looking great - good work

Did anyone else come across this error message at runtime?

ArgumentError: Error #2082: Connect failed because the object is
already connected.
        at flash.net::LocalConnection/connect()
        at YouTube/init()
        at YouTube()
        at youtubeDC/init()
        at youtubeDC()


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Garth  
View profile  
 More options Jun 8 2008, 9:17 pm
From: Garth <therealga...@gmail.com>
Date: Sun, 8 Jun 2008 18:17:04 -0700 (PDT)
Local: Sun, Jun 8 2008 9:17 pm
Subject: Re: Sample Code: Using the API with AS3
For all of us "Flex-only" developers, I have taken the great tips here
and created a working Flex demo and a wrapper SWF that you can use
directly with Flex if you don't want to or can't make your own.

http://otoh.typepad.com/on_the_other_hand/2008/06/embed-the-youtu.html


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Qabiz  
View profile  
 More options Jun 15 2008, 2:26 pm
From: Abdul Qabiz <abdul.qa...@gmail.com>
Date: Sun, 15 Jun 2008 11:26:39 -0700 (PDT)
Local: Sun, Jun 15 2008 2:26 pm
Subject: Re: Sample Code: Using the API with AS3
Great stuff mentioned here, just wanted to add a few things:-

1) How to instantiate many YouTube objects?

You need to have unique name for LocalConnection, that can be done by
creating pair of unique names (prefix+ Math.random () * currentTime)
in AS3 wrapper, pass these names to AS2 wrapper (for youtube player)
via query-string while making _loader.load (..). That way you can use
exchange the localconnection names.

This approach does have a disadvantage which is, AS2 wrapper swf would
not be used for next session because browser would AS2_Wrapper_SWF_URL
+ unique_query string, so for each session effective URL is different.

If your AS2 wrapper SWF is light-weight, this is no issue. So keep
your controls in AS3 to keep AS2 Wrapper SWF lightweight

2) How to get values like volume, videoBytesLoaded, videoBytesTotal,
state, etc?

There could be many ways, the way I thought, I would keep AS3 wrapper
up to date all the time, which can be done either by using a Timer in
AS2 Wrapper or event or both

a) Keep state in AS3 variable and update it whenever LC invokes state-
change handler in AS3
b) Volume - it can be done either via set-interval or other methods
which updates this
c) isMuted - Updated it whenever mute (..) method of AS3 wrapper is
called, actually you are maintaining states in AS3 instead of relying
on AS2 wrapper. I believe, you might have to sync it since YouTube
player persists the user preferences in SharedObject, so its not bad
idea to update these fields in AS3 once AS2 wrapper successfully loads
ytplayer.swf

This is what I have thought of and going to implement in the wrapper.

Thanks for sharing the code and ideas, it got me started easily.

-abdul

On Jun 9, 6:17 am, Garth <therealga...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
zdravko  
View profile  
 More options Jun 15 2008, 11:08 pm
From: zdravko <email.workBe...@gmail.com>
Date: Sun, 15 Jun 2008 20:08:34 -0700 (PDT)
Local: Sun, Jun 15 2008 11:08 pm
Subject: Re: Sample Code: Using the API with AS3
Abdul,

Might you end up building on Garth's contribution and then posting it
back ;?)

Thanks,
zdravko


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dehash  
View profile  
 More options Jun 17 2008, 12:01 pm
From: dehash <deh...@googlemail.com>
Date: Tue, 17 Jun 2008 09:01:20 -0700 (PDT)
Local: Tues, Jun 17 2008 12:01 pm
Subject: Re: Sample Code: Using the API with AS3
Good example Garth. Could be my error but the volume/mute control
works only for the first video played. Been looking into adding a
youtube feed grabber to load files dynamicaly or via user search using
the same API as you did.

dehash

http://www.dehash.com

On Jun 9, 2:17 am, Garth <therealga...@gmail.com> wrote:


    Reply to author    Forward