# Help with YouTube player through IMVU Flash Widget API

**URL:** <https://forum.kirupa.com/t/help-with-youtube-player-through-imvu-flash-widget-api/332077>\
**Category:** flash\
**Created:** [January 20, 2014, 3:20am UTC](https://forum.kirupa.com/t/help-with-youtube-player-through-imvu-flash-widget-api/332077 "2014-01-20T03:20:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![snapz](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@snapz](https://forum.kirupa.com/u/snapz)\
**Post date:** [January 20, 2014, 3:20am UTC](https://forum.kirupa.com/t/help-with-youtube-player-through-imvu-flash-widget-api/332077/1 "2014-01-20T03:20:21Z")

</div>

I am looking into creating a YouTube video search and play widget for inside IMVU’s Widget API.  
Here is the link to download the getting started files needed from IMVU:

[http://code.google.com/p/imvu-flash/downloads/list](http://code.google.com/p/imvu-flash/downloads/list) and click the link to download the zip.

Everything needed is there.

Actionscript 3 code written with Flash CS3:

.fla file only consists of a rectangle window movie clip (any color) with 100% alpha using Document Class of YtubeWidget.

package {  
// Needed for package to work through IMVU API

```
import com.imvu.widget.*;
import com.imvu.events.*;
import flash.system.Security;
import flash.events.*;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
Security.allowDomain("*"); // Can be ("w.w.w.youtube.com") also. 

//Class needed for IMVU API

```

public class YtubeWidget extends ClientWidget {

```
    // My variables

```

public var my\_loader:Loader = new Loader();  
public var my\_player:Object;

```
    // Function to initiate widget inside IMVU pipeline and add to stage

```

public function initWidget(event:Event):void {  
//trace(“init”);  
this.widgetName = “YtubePlayer”;  
this.space.addEventListener(com.imvu.widget.WidgetSpace.WIDGET\_LOADED, addWidgetToStage);

```
        //YouTube URL call

```

my\_loader.load(new URLRequest(htp://w.w.w.youtube.com/apiplayer?version=3")); //(\<reconfigure)  
my\_loader.contentLoaderInfo.addEventListener(Event.INIT, addWidgetToStage);

```
    }

    // Remove Listener

```

public function addWidgetToStage(event:Event):void {  
this.space.removeEventListener(com.imvu.widget.WidgetSpace.WIDGET\_LOADED, addWidgetToStage);  
my\_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, widgetLoaded);

```
    }

    // Adding loader from YouTube

```

public function widgetLoaded(event:Event):void {  
addChild(my\_loader);  
my\_player = my\_loader.content;  
my\_loader.content.addEventListener(“onReady”, onPlayerReady);

```
    }

    // Loaded video request

```

public function onPlayerReady(event:Event):void {

// YouTube ID for video explaining, but outside of a package needed in this code  
//Full link: [https://www.youtube.com/watch?v=gLkB00Fj0bw](https://www.youtube.com/watch?v=gLkB00Fj0bw)  
my\_player.loadVideoById(“[gLkB00Fj0bw](https://www.youtube.com/watch?v=gLkB00Fj0bw)”,0);  
my\_player.setSize(640,480);

```
        } 

```

}

}  
// Stop

This is just to get the YouTube Chromeless player into the IMVU test environment!

This code shows no errors in compiler, but won’t pull video loader to stage request.

This is how I understood IMVU’s ways to test inside their Mock Server and Mock Client SWF’s (Included in API zip and how to use it).

If anyone knows about the IMVU API and can show me where I went wrong or why the YouTube call for the loader wont load in the test environment, please post answers.
