Play youtube videos in flash tutorial
Like i promised many of you , here is a quick video tutorial on how to load youtube videos in flash , the only thing is im running out of time and i have many other projects to deal with so its a kinda fast so Listen and watch carefully , if you have a question regarding the tutorial you can always post a comment .
Things to remember :
- AbdulQabiz youtube php engine that is downloadable with the example sourcecode ( Many thanks to him ) .
- Dont forget to get your own developer ID since all the rest requests requiers the dev id e.g:
http://www.youtube.com/api2_rest?method=youtube.users.get_profile&dev_id=YOUR_DEV_ID
NOTE THAT YOU WONT NEED A DEV_ID IF YOU WILL MANUALLY ADD THE YOUTUBE VID LINKS . - Read the INTRODUCTION and the DOCUMENTATION .
Things to consider :
The application i built at http://www.zainals.com/xperments/youtube is reading the XML file from youtube , now i didnt explain much about that because its a different topic but if you would like , i can make another video about xml when im free , but for the time being google it , you can find many tutorials at kirupa gotoandlearn.com and tutorialvid.com
Unfortunatly youtube disabled or changed their crossdomain xml file as mentioned on abdulqabiz blog , and will have to use some sort of a proxy script e.g :
<?php
$dataURL = "http://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_id=YOURDIV_ID";
//note that this will not follow redirects
readfile($dataURL);
?>
Enjoy the following vid … Enlarge the vid for a clearer preview …

July 5th, 2007 at 8:20 am
Nice, man. I downloaded the CS3 trial, so I’ll get a dev ID and try this out today.
By the way, the missing email from the photo upload arrived yesterday. It must have come by boat or something.
Later!
July 5th, 2007 at 10:40 am
Hey Mank
good to know that you downloaded that , remember to set your publish settings to Actionscript 2.0 when following my tut because im still working on that version .
lol @ the boat , probablly DNS or Queue issue …
if you need help you know where to find me !
July 5th, 2007 at 12:47 pm
lol after watching my vid (which i made quickly at work) its really not that clear but it should give you some idea about it …. ( i sounded sleeepy )
i also recommend that you watch the XML videos by Lee >> :
XML basics :
http://www.tutorialvid.com/viewvideo/558/Flash_Tutorial_XML_Basics/?ref=actionscripter
XML video play list :
http://www.tutorialvid.com/viewvideo/559/XML_Video_Playlist___Flash_Tutorial/?ref=actionscripter
July 11th, 2007 at 7:07 am
Hi my name’s Cory I couldn’t get my flash file for this tutorial right it says something like
*** Security Sandbox Violation ***
Connection to “http://www.youtube.com/get_video.php?video_id=” . $v . “&t=”. $t . “&flv halted - not permitted from
Is it ok if you can send me the flash file along with the php file for this tutorial? I’ll be grateful !
my email is:********************
Thank you very much
Cory
July 11th, 2007 at 11:18 pm
Hi Cory , i have removed your email so you dont get spammed …

when security sandbox appears it means that another domain is trying to access the current player domains , you can avoid this by adding the following code at the top of your actions layer :
System.security.allowDomain("*");
read more about it on adobe technote or livedocs .
but from what i see the recieved variables are not shown , its like the PHP code is not proccessed and returns basic TEXT string …
here are the files :
files
August 7th, 2007 at 9:20 am
Im really stuggling with this, have been trying for hours now. I can construct the url ok using the php script, and remake the url in flash ok as well, if i paste this url in a browser i can even download the .flv file.
However if i use the path as the .contentPath it will not load the movie, i just get this error in the trace window
1005: Invalid xml: URL: “http://www.youtube.com/get_video.php?video_id=s1fz8pYly9k&t=OEgsToPDskJlt-hGmLAioouhnfwj6FxF&.flv&FLVPlaybackVersion=1.0.1″ No root node found; if url is for an flv it must have .flv extension and take no parameters
if you can help i will be very grateful!
August 7th, 2007 at 12:56 pm
hi mate …
like the error said , there is something wrong with your variable out put , which is in your case “http://www.youtube.com/get_video.php?video_id=s1fz8pYly9k&t=OEgsToPDskJlt
-hGmLAioouhnfwj6FxF&.flv&FLVPlaybackVersion=1.0.1″
now to get the flv playing in your application the extension at the end should be only .flv
here is a sample that you can download , have a look properly and fix your code a bit to get the proper output http://www.zainals.com/loads/blog/xperments/youtube.rar
let me know how this goes i’ll be glad to sort it out for ya .
September 1st, 2007 at 8:35 pm
tnx man u explain well good job
September 27th, 2007 at 12:08 am
Hi
I have developed a similar kind of application to view you tube videos. It works perfectly as a standalone desktop application but when i put it on the server and try to run it on the web i am not gettin any outputs.. can anyone help me out with this.
September 27th, 2007 at 4:52 am
*
Actually the problem is when i run the application from a server I am not able to retrieve the xml from the specified path (i.e http://gdata.youtube.com/feeds/videos?…. )
can anyone please help me out with this!
October 24th, 2007 at 10:08 pm
@Arun:
> Actually the problem is when i run the application
> from a server I am not able to retrieve the xml from
> the specified path (i.e
That’s because Google/YouTube doesn’t have liberal crossdomain.xml, their policy file only allows Google’s properties.
You can use a server-side proxy to route your requests..
-abdul
November 3rd, 2007 at 1:05 pm
Hey What happened with the video
I came to watch your video again but it is not published anymore, how can I do to watch it again?
sorry for my bad english…
December 9th, 2007 at 3:54 am
Heres another example
http://jaxxrr.110mb.com/other/fs3.html
and heres the sourcecode
http://jaxxrr.110mb.com/other/flash-fullscreen-youtube.zip
the fullscreen part is nothing special really.. one line of script on a button
on (release) {
)
Stage.displayState = “fullScreen”;
}
but you also need to edit the html file and set the allowFullScreen parameter from false to true, it is there just set it to true (don’t write it twice like I did
so either
…
or
AC_FL_RunContent( … “allowFullScreen”, “true”, … )
depending on how you launch the flash..
Also make sure your html file does’nt get overwritten when publishing again.. go to publish settings and uncheck html
this info is also in flash CS3 help
cheers
February 11th, 2008 at 6:18 am
I’m trying to load 3 different youtube videos in a movie depending on 3 buttons.
My code is:
pest_1.onRelease = function() {
_root.createEmptyMovieClip(”mc”,0); unloadMovie(mc);
loadMovie(”http://www.youtube.com/v/HO-BcoXYGuA&autoplay=1&noscale=true”,mc);
mc._x=15;
mc._y=40;
mc._xscale=90;
mc._yscale=80;
}
pest_2.onRelease = function() {
unloadMovie(mc);
loadMovie(”http://youtube.com/v/zUjMMKuzBPQ&autoplay=1&noscale=true”,mc);
}
pest_3.onRelease = function() {
unloadMovie(mc);
loadMovie(”http://youtube.com/v/ZjHMSE7-oME&autoplay=1&noscale=true”,mc);
}
stop();
I really don’t know why, i can see the first two videos. When i try to load the third, the movieclip show grey and any video can be played anymore.
The tutorial you made isn’t aviable anymore. Can you give me some advice?
February 11th, 2008 at 6:36 am
i fixed the vid mate , i dont know what is exactly going on with your script , i need sometime to see it , busy at the moment …

February 14th, 2008 at 3:45 pm
If you get into some errors, like 1005;
try to handle your php/asp flv-rendering-source in Flash like:
your-path-way/to/heaven/ STREAM-HANDLER . php / anything-here.flv
.php COULD be .asp here, :-p
Flash adds ?xxxx to the file, so faking an extension in any other way won’t work.
March 5th, 2008 at 4:02 pm
Hi,
does your example suitable for actionscript 2.0 ?
If it is, how did you solved the cross domain problem ?
Ho do I make AbdulQabiz youtube php engine work in actionscript 2.0 ?
Sallaboy
May 18th, 2008 at 7:26 am
I read a lot of articles to play a youtube video in flash/ flex and now I’m lost!! I don’t understand! Is there an easy way to play a youtube video in Flash/Flex without have a sandbox error now? I follow an example on abdulblog but now, without the “free crossdomain.xml” , we can’t play a youtube video without have an sandbox error. So how we can? You talk about a server side proxy but I don’t understand how it can be use to play the video. To retrieve XML, I understand, but to play the video into the flash I don’t understand. Please help if you have a way to resolve!
August 27th, 2008 at 7:24 am
Error opening URL ‘http://www.youtube.com/v/PAlNMaxZVTk
how do I solve this issue