I am trying to following the tutorial of this website for youtube API.
http://www.zedia.net/2009/how-to-load-a-youtube-movie-into-flash-using -tubeloc/
I have downloaded the tubeloc and copied the neccessary files to my src folder and have the following codes.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
xmlns:components="components.*">
<fx:Script>
<![CDATA[
import com.enefekt.tubeloc.MovieSprite;
import com.enefekt.tubeloc.event.*;
var youtubeMovie:MovieSprite = new MovieSprite(null, true);
youtubeMovie.addEventListener(PlayerReadyEvent.PLAYER_ READY, onPlayerReady); //problem code
addChild(youtubeMovie); //problem code
function onPlayerReady(event_p:PlayerReadyEvent):void {
//it's just cleaner to remove listener that won't be used again
youtubeMovie.removeEventListener(PlayerReadyEvent .PLAYER_READY, onPlayerReady);
//you can set the size of the movie this way
youtubeMovie.width = 370;
youtubeMovie.height = 276;
youtubeMovie.loadVideoById("tprMEs-zfQA");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<components:videoList />
</s:Application>
However, I got the errors as following.
Access of undefined property onPlayerReady
Access of undefined property youtubeMovie
Access of undefined property youtubeMovie
Call to a possibly undefined method addChild.
I have declared those properties and I thought addChild is imported by default. How am I getting these ridiculous errors? Any thoughts? Thanks for the help.
In MXML, these lines...
youtubeMovie.addEventListener(PlayerReadyEvent.PLAYER_ READY, onPlayerReady);
addChild(youtubeMovie);
... need to be inside an event handler, for instance for the creationComplete event. To create an event handler, go to the tag at the top of your .mxml file, start typing creationComplete and use code completion to create the handler. Then put these two lines inside the handler.
Furthermore, in the Flex world we don't use addChild, we use addElement. But addElement doesn't accept MovieClips, because there is some complicated measuring and positioning going on behind the scenes which MovieClip doesn't implement. The SpriteVisualElement control can take care of that for you. Add a SpriteVisualElement to your mxml, then do an sve.addChild(youtubeMovie).
This should answer your previous question as well, btw
North America
Europe, Middle East and Africa
Asia Pacific