YouTube AS3 API (onReady doesn't work more ?) - actionscript-3

YouTube AS3 API . This simple code was writed long time ago . and all was ok .
But some days ago some problems.
Early (up to 18th this month) all working OK.
Flash player using AS3 API.
public function Main()
{
super();
Security.allowInsecureDomain("*");
Security.allowDomain("*");
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.SHOW_ALL;
this._loader = new Loader();
this._loader.contentLoaderInfo.addEventListener(Event.INIT,this._onLoaderInit);
this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.errorHandlerIOErrorEvent);
this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.errorHandlerIOErrorEvent);
this._loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,this.onUncaughtError);
this.loadTime = new Date();
this._loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3");
}
private function _onLoaderInit(param1:Event) : void
{
this.player = this._loader.content;
this.player.addEventListener("onReady",this.onPlayerReady);
this.player.x = 0;
this.player.y = 0;
addChild(DisplayObject(this.player));
this._loader.contentLoaderInfo.removeEventListener(Event.INIT,this._onLoaderInit);
this._loader = null;
}
function onPlayerReady(param1:Event) : void // start from 18th this month , onReady dont fired
{
}
is somebody know this issue , or how fix it ?
Thx .

#Ivan Korneev
This is the answer. The YouTube API for AS3 (Flash) has been depreciated. I know this because it just broke in our application a few days ago, luckily we moved over the HTML5. I suggest you do the same. You can learn more here https://developers.google.com/youtube/iframe_api_reference

Thx to #All for responses.
I found some intresting thing .
apiplayer.api have function in class DirectAccessAPI
protected function forwardAPICall(param1:String, param2:Array)
{
var _loc_3:* = new APICallEvent(this.API_CALL, param1, param2);
this.loader.contentLoaderInfo.sharedEvents.dispatchEvent(_loc_3);
return _loc_3.returnValue;
}// end function
but API_CALL constant is member of APICallEvent ,
i just fix it like this
var _loc_3:* = new APICallEvent(APICallEvent.API_CALL, param1, param2);
and all ok , but now i need load apiplayer from local storage , not from youtube.

I've encountered the same issue. I use this API to display a Youtube video (chromeless player) within a flash-based game. So, sadly I'm unable to switch to the HTML5 player, as it doesn't work inside Flash. As I'm stuck with the Flash-based Youtube API, I've tried to solve this issue like OP.
After some investigations, I've found that:
- The host address of the API have been moved around February 18th. (now on the googleapis.com domain instead of youtube.com)
- After this domain move, the API is unable to load correctly from Youtube. As described in the doc, when you load the API, it should trigger a "onReady" event. Currently, that never happens.
- Calling any method described in the doc (loadVideo(), stopVideo(), etc.) on the player will now result in a "method X() doesn't exist" error. So it's not just the "onReady" event no firing, but that the API is failing to load itself
- A further proof that something is wrong with the Flash Player API on Youtube side, is that opening the chromless player URL in a browser no longer display a "Youtube" logo, as it used to be.
- My suggestion would be that they forgot to rewrote some inner URL when they moved the API from a domain to another, and now it can no longer load all its dependencies or something like that.
Unfortunately, this doesn't solve the problem, just refine where it is.
I think the only way would be to get in touch with Youtube so they "fix" whatever is wrong with their current API. Unless they disabled it voluntarily (which would be sad, as HTML5 can't cover all the uses the AS3 player did).

Try https for Youtube path. Eg: .load(new URLRequest("https://www.youtube.com/api...etc
Instead of http://www.youtube.com/apiplayer?version=3
try: https://youtube.googleapis.com/apiplayer?version=3

try this open source solution https://github.com/myflashlab/AS3-youtube-parser-video-link

Related

Recording using Flex/Flash

I know that we can not record/Access anything out of flash player, because of it's security sandbox.
Instead We can record the video while streaming it to server.
like
netStream.publish("YourFileName.flv","record");
But in recorde file, I will get only a video file Published by webcam to server and i want to record entire session.
Is there any way to record it locally, or Can i record the window ??
p.s. : I am not trying to access anything outside of flash player.
Thanks in advance...
ok, so you can record the entire contents of the swf like this:
first, create a container object (anything that extends DisplayObject which implements IBitmapDrawable) then place everything that you want to capture (video view and everything else in your "session") then using an ENTER_FRAME event or Timer (preferable to control capture fps), draw the container to a BitmapData using BitmapData.draw(container). Pass that BitmapData to the FLV encode library found here using it's addFrame() method (docs and examples come with that library... super easy) and that's it! When you are done, you will have an flv video containing a frame by frame "screen capture" of what was going on in your swf! Just make sure EVERYTHING is in the container! That lib also accepts captured audio too if you want.
private function startCapturing():void{
flvEncoder.start(); // see the libs docs and examples
var timer:Timer = new Timer(1000/15); //capture at 15 fps
timer.addEventListener(TimerEvent.Timer, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void{
var screenCap:BitmapData = new BitmapData(container.width, container.height);
screenCap.draw(container);
flvEncoder.addFrame(screenCap); // see the libs docs and examples
}

AS3 POST png to PHP

Have read many similar but no solutions: I'm trying to do something (that i think is) really simple,
Take a photo from gallery or camera - and POST this to a URL. No saving / returning to application. The PNG is just used by the webpage in display and user moves onward.
public function postPicture():void {
PNGEncoder2.level = CompressionLevel.FAST;
var encoder : PNGEncoder2 = PNGEncoder2.encodeAsync(_bitmapData);
encoder.targetFPS = 12;
encoder.addEventListener(Event.COMPLETE, function (e):void {
var png : ByteArray = encoder.png;
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("https://myurl.com/mypage");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = png;
navigateToURL(jpgURLRequest, "_blank");
});
}
Also to note, we're getting some odd characters on the end of the URL: C9%90NG
Hunch is that I'm decoding and then not encoding properly before sending i.e. these characters some part of raw image info.
When I test from chrome POST extension with another image, server side stuff works fine so guessing a problem with AS3.
basically its working when I use chrome to browse > my.png and POST it at the page. Am I missing something with the AS3 png encoder? i.e. how to turn that bmpdata into a 'file' rather than an array of bytes.
thankyou
You need to use multipart upload. It's a common situation with a well defined standards for that. You can implement it by yourself but it will take some time and efforts.
What I've used before is the Multipart URLLoader Class provided by Eugene Zatepyakin, one the best Flash guru's out there :)
It's some kind of old but does the job extremely well. You can add variables, files, whatever content you want to your loader and simply submit it. There are examples with the php side of the thing so you can understand what's going on.

Swiffy - set up a clicktag - syntax issue

I am working with Flash CS6 / AS3 exported with Swiffy for HTML 5.
I would like to include a clickTag on a simple button but cannot find the proper syntax.
The basic code below, generated by Flash works fine:
this.myButton.addEventListener("click", fl_ClickToGoToWebPage_2);
function fl_ClickToGoToWebPage_2() {
window.open("http://www.mysite.com", "_blank");
}
Then I added the javascript code given by Google Swiffy to set the variable in the webpage (no bug so far):
stage.setFlashVars("clickTAG=http://www.mysite.com");
stage.start();
In Flash (AS3), I tried the usual code:
var paramList:Object = loaderInfo.parameters;
var urlRequest:URLRequest = new URLRequest(paramList["clickTAG"]);
function fl_ClickToGoToWebPage_2() {
window.open(clickTAG, "_blank");
}
But that does not work :( and the variable does not come through. This even bugs the animation.
Question is, how should I write the Flash code lines to get the variable passed to my window.open function? What I am missing?
Thanks a lot for you help
If you are sure that clickTAG is correctly set, try the method at this link using navigateToURL:
Is there a way to get values form a swiffy animation
Send your link string from the swiffy to a javascript function & do your window.open stuff there.

Embedded Image not Adding to Stage

So I have an image that I'm trying to embed to use as a sprite sheet. My problem is that I am receiving no errors at all, but my image can't even be added to the stage. It's like nothing is being loaded at all.
I am using the Flash CS 5.5 compiler. Here is my code:
public class Game extends MovieClip {
[Embed(source='../assets/images/sprite_sheet_1.png')]
private var sheetClass:Class;
private var sheet:Bitmap = new sheetClass();
public function Game() {
addChild (sheet);
}
}
I've also tried fiddling with the x and y values to make sure nothing is just covering it up and I can't see any problems with that, either. It's just not showing up.
I don't understand why it's not working as intended. Any aid would be fantastic. Thanks!
P.S. - I'm trying to embed the sprite sheet because someone recommended it would be a better route than just using URLLoaders, but is that necessarily true? Is it just true because we are talking about sprite sheets for a smallish Flash game?
You need to check a checkbox called something like "Export SWC" under the publish settings. I'm not sure of the exact phrasing because I don't have the same version of Flash that you have.
See this page and this page

Going from Flash 8 to CS3

After many years of using Flash 8, I'm moving to CS3 at work. I know I'll have to learn AS 3.0 so, does anyone have any good references or summaries of the major/most noticeable changes? Also, are there any tips/tricks for the flash environment? After spending a few minutes in CS3, I noticed that you can't directly attach actionscript to a button, which is new to me. Any other such pitfalls to watch over?
I made the total switch just about 3 months ago, here are some things that helped me ramp up rather quickly:
1) Do everything in Class files
A lot of AS3 tutorials out there deal with just code pasted on the timeline (which I can't stand because now you have to hunt for what import you need), but is fine for quick tiny stuff. In the long run it's way better work primarily in Class files. Learning how Classes work opened a huge door for me, it was the same feeling/experience I had when I first discovered Functions in AS2 :)
2) Keep graphics in library and off the workspace
Example, you have a jpg, gif, png file you just imported into your library. Made a movieClip and gave it a class name(MyButton). Now the code below will place the graphic into the workspace for you:
var myButton:MovieClip = new MyButton();
myButton.x = 6;
myButton.y = 22;
myButton.buttonMode = true;
addChild(myButton);
3) Get use to the new button code in AS3
It's something all of us new converts had to deal with painfully, but now it's a piece of cake :)
myButton.addEventListener(MouseEvent.MOUSE_UP, clickThis);
function clickThis(event:MouseEvent):void
{
navigateToURL(new URLRequest("form.html"), "_self");
//navigateToURL(request, '_self');
}
4) Make sure you remove Event Listeners after use
It took me a bit to wrap my around this one... remove em why? Oh they are still running in the background and when I listen again I'll get all kinds of mutated errors.
private function volDown(e:MouseEvent):void
{
masker.width = volControl.mouseX;
userVolume = (masker.width / 100) * 1;
volControl.addEventListener(MouseEvent.MOUSE_MOVE, volMove);
}
private function volUp(e:MouseEvent):void
{
lastVolPoint = masker.width;
setVolume(userVolume);
e.updateAfterEvent();
volControl.removeEventListener(MouseEvent.MOUSE_MOVE, volMove);
}
5) Don't forget to pass Events
I'm not a programmer by trade and this has caused so much grief, I'm glad I'm done with this birthing pain:
myButton.addEventListener(MouseEvent.MOUSE_UP, clickThis);
Since the clickThis function is launched via an Event, you have to pass: event:MouseEvent into it like so:
function clickThis(event:MouseEvent):void
Because the code below will throw the dreaded AS3 "Access of undefined property" error that new AS3 guys will always run into.
function clickThis():void
6) Read and post questions on StackOverflow... a lot!
btw I'm still a noob and originally a designer then AS2 dev, I still don't know why we put :void behind a function name.. if we have similar coding backgrounds I hope all that helps :)
I suggest you to look at the ActionScript language migration page on the Adobe devnet. It offers quite a lot articles about the key changes with ActionScript 3.
To answer your problem with the actions on a button, this no longer works (and was already with ActionScript 2 not the best way to do it). AS3 requires the code to be centralized on the timeline. So for giving a button some action, you'll need to give it an instance name and add an event listener for the CLICK event, like this:
function doSomething ( event:MouseEvent ):void
{
trace( "test" );
}
myButton.addEventListener( MouseEvent.CLICK, doSomething );
Get an Actionscript 3 IDE. Such as Flash Builder, FlashDevlop, or FDT. This will force you to learn really fast.