Flash content not go full screen - actionscript-3

I have found this but it is supposed to work as swf in the desktop, not in the html.
I am trying to make the content full screen via both at the beginning of the code and mouse event. However stage.displayState returns null. Here is how I do things;
at the beginning:
stage.displayStatus = StageDisplayState.FULL_SCREEN_INTERACTIVE;
and then
fullScreenButton.addEventListener(MouseEvent.CLICK, DoFullScreen);
function DoFullScreen(e:MouseEvent)
{
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
and in the function, stage.displayState traced null as I said before.

You need to target FP 11.3+ for StageDisplayState.FULL_SCREEN_INTERACTION
for below versions : StageDisplayState.FULL_SCREEN
and you have to add that flash param in your html
<param name="allowFullScreen" value="true" />
I added the sample swf and fla

Related

recreating the old youtube mobile player whit flash

i have an old "smartphone", since youtube killed the old flash player (html5 video doesn't work and it has so few ram that i can't even load the full "the old net"
i never worked whit flash before (and i never really did anything similar)
the basic idea is to make an host a simple html page that ask you the id of the video, it download it, downscale it to 144p, convert in flash and send it to the phone
the problem is, i don't know how to use the buffering, so it work whit short videos, but when they're too long it fail to buffer everything when loading the page and break
i would like something like how youtube work (load piece by piece)
any ideas on how should i do this?
btw, the old phone is a samsung GT-S5260 whit samsung dolfin 2.0
Ok, my AS3 is kinda rusty already, but I think it should work as the following.
First, you pass the video URL to the Flash application via FlashVars, it is a special HTML tag.
If you form HTML tags outright (figure urls and dimensions on your own):
<object width="640" height="480" type="application/x-shockwave-flash" id="X" name="X" data="flvplayer.swf" >
<param name="movie" value="flvplayer.swf">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />
<param name="quality" value="high" />
<param name="wmode" value="opaque">
<param name="FlashVars" value="flvurl=movieurl.flv" />
<embed width="640" height="480" type="application/x-shockwave-flash" id="X" name="X" src="flvplayer.swf"
allowScriptAccess="sameDomain"
allowFullScreen="true"
quality="high"
flashVars="flvurl=movieurl.flv"
pluginspage="http://www.adobe.com/go/getflashplayer"
></embed>
</object>
Alternately, if you activate the Flash application through the SWFObject:
<script type="text/javascript">
var flashvars = {
"flvurl=movieurl.flv"
};
var params = {
allowScriptAccess: "sameDomain",
allowFullScreen: "true",
wmode: "opaque",
quality: "high",
menu: "false"
};
var attributes = {};
swfobject.embedSWF("flvplayer.swf", "X", "640", "480", "9.0.0","expressInstall.swf", flashvars, params, attributes);
</script>
Ok. Next step, you need the means to build that flvplayback.swf. In order to do so, you need either AIR SDK or Flex SDK (optionally FlashDevelop tool because it made things so much easier back then, auto-downloaded SDKs too, but I have no idea if it works these days) or Flash/Animate IDE. I believe it is still possible to find some kind of tutorial like "build my first Flash project".
Then, the very application in question is rather simple one. The one below goes in a form of a single class, which should be the main class if you build thru AIR/Flex SDK or assigned as the document class if it is Flash/Animate.
package
{
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.events.Event;
import flash.display.Sprite;
public class Main extends Sprite
{
private var playback:Video;
public function Main()
{
// Being able to access the stage is important.
if (stage) onStage(null);
else addEventListener(Event.ADDED_TO_STAGE, onStage);
}
private function onStage(e:Event):void
{
// The fact we are here means the stage is present and available.
removeEventListener(Event.ADDED_TO_STAGE, onStage);
// Obtain the video URL.
// That's why being able to access the stage was important.
var flvurl:String = stage.loaderInfo.parameters["flvurl"];
// If there's no URL provided, just stop.
// Normally I'd put some visual alert here.
if (!flvurl) return;
// Set up stage a bit.
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.stageFocusRect = false;
stage.showDefaultContextMenu = false;
// Build and start the video player.
var NC:NetConnection;
var NS:NetStream;
NC = new NetConnection;
NC.connect(null);
NS = new NetStream(NC);
NS.play(flvurl);
flvplayback = new Video;
flvplayback.attachNetStream(NS);
// Make it the size of the stage right away
// then subscribe to any size changes.
onResize(null);
stage.addEventListener(Event.RESIZE, onResize);
// Finally, attach the video player to the display list.
addChild(flvplayback);
}
private function onResize(e:Event):void
{
flvplayback.width = stage.stageWidth;
flvplayback.height = stage.stageHeight;
}
}
}
I cannot promise this would work right away, although I think it probably will. The idea is correct, the logic is straight, I just might forgot something or made some typos.

Issues with embedding objects using htmlloader

I'm making an editable stage where the user can add images, videos, and embedded content. Currently all objects reside in a classfile called Space. All objects that you can add go inside of bounds_mc inside of space. Those objects are called SpaceObjects and are handled by the classfile SpaceObject...
Right now, when I tell my SpaceObject to add an embed it does it, but..there's a bit of an issue.
When I add the object I can't exactly interact with it. I am able to highlight it with the same mouse icon that you would see when highlighting text..but nothing else. I can move bounds_mc around just fine (the white space behind it) and have that object move accordingly..but nothing else.
Now if I add this object directly to the stage by passing the stage all the way down to my Space class and doing a stagee.addChild(htmlLoader) this issue is resolved.
At first I thought this was because it was inside a bunch of movieclips or some kind of order issue in the displaylist...but that was disproved by this testrun.
I have the HtmlLoader inside of three movieclips and I'm able to interract with the embedd just fine. I'm trying to figure out what could be causing this. I've tried switching where HtmlLoader goes from here to there but I still get this issue.
Here's the embedd
<iframe width="560" height="315" src="https://www.youtube.com/embed/Kzgjiuvpmsk" frameborder="0" allowfullscreen></iframe>
Here's a sample from my Space class that handles user input from the menu.
case "embeddedobject":
trace("Embeddedobject");
//For now, just testing a standard embedd from youtube. Dynamics later.
var so:SpaceObject = new SpaceObject("embeddedobject", '<iframe width="560" height="315" src="https://www.youtube.com/embed/Kzgjiuvpmsk" frameborder="0" allowfullscreen></iframe>', new Rectangle(rightMouseX, rightMouseY));
bounds_mc.addChild(so);
//Tested with and without the eventlistener..same results
so.addEventListener(MouseEvent.CLICK, contentClickHandler);
spaceObjects.push(so);
break;
This is an excerpt from SpaceObject. It handles the arguments passed from it's constructor. In this case its generating my embedd. The first argument is source. the second is actions (the string of the embedd)
public function SpaceObject(source:String, actions:String, bounds:Rectangle, rotation:int=0, matrixx:Matrix = null)
{
//...
if (source == "embeddedobject")
{
htmlLoader = new HTMLLoader();
htmlLoader.placeLoadStringContentInApplicationSandbox = true;
htmlLoader.loadString(actions);
htmlLoader.addEventListener(Event.COMPLETE, handleHtmlLoadComplete);
}
//...
}
private function handleHtmlLoadComplete(e:Event):void
{
trace("Html content load complete");
htmlLoader.removeEventListener(Event.COMPLETE, handleHtmlLoadComplete);
htmlLoader.width = htmlLoader.contentWidth;
htmlLoader.height = htmlLoader.contentHeight;
addChild(htmlLoader);
}
Here are the links to the classfiles involved that I've made on pastebin.. all space objects reside in Space. Space resides in SpaceContainer.
SpaceContainer.as
Space.as
SpaceObject.as
Edit 12/5/15: An interesting note. When clicked on, e.target is returned as a sprite. When other objects are clicked on (be it images or videos) they're returned as my SpaceObject. This happens both at times when I add it to the stage, and when I add it to bounds_mc.
e.target = [object Sprite] vs e.target = [object SpaceObject]
Edit 12/5/15: Looks like any alteration of the objects (aside from its x and y) disables any interactive objects inside the embed and turns it into some kind of bitmap.
Resizing.
It looks like when you resize or alter any displayobjects that are containing the embed (either before or after you place the object) it will disable the embed.
This line was in main.as and was constructing SpaceContainer.
var sc:SpaceContainer = new SpaceContainer(stage);
//resize(sc, stage.stageWidth, stage.stageHeight);
...
private function resize(mc:DisplayObject, maxW:Number, maxH:Number = 0, constrainProportions:Boolean = true):void
{
maxH = maxH == 0 ? maxW : maxH;
mc.width = maxW;
mc.height = maxH;
if (constrainProportions)
{
mc.scaleX < mc.scaleY ? mc.scaleY = mc.scaleX : mc.scaleX = mc.scaleY;
}
}

AS3 - use of stage in an external swf

I've purchased a custom chromeless youtube video player. The original intended use of this is to be embedded into an HTML page... however for my needs, it must be loaded as an external swf into another container swf.
The problem is that "stage" is referenced several times throughout the code of this player.
For instance to go to full screen mode, this is used:
function fsClick(e:MouseEvent) {
if(controls.fsBtn.currentFrame == 10) {
stage.displayState = StageDisplayState.FULL_SCREEN;
controls.fsBtn.gotoAndStop("backToNormalOver");
}
else {
stage.displayState = StageDisplayState.NORMAL;
controls.fsBtn.gotoAndStop("goFsOver");
}
}
another example:
//stage resize event
stage.addEventListener(Event.RESIZE, onStageResize);
function onStageResize(e:Event):void{
stage_width = stage.stageWidth;
stage_height = stage.stageHeight;
player.setSize(stage_width,stage_height);
controls.x = (stage_width - controls.width)/2;
controls.y = stage_height - 40;
stageOver(null);
if (stage.displayState == StageDisplayState.NORMAL) {
controls.fsBtn.gotoAndStop("goFs");
}
topBar.titleBar.width = stage_width;
topBar.theTime.x = stage_width - topBar.theTime.width -10;
topBar.theTitle.width = stage_width - 180;
}
Now, the problem as you have already guessed, is that "stage" is no longer relevant in this context as it refers to the container's stage and not this swf's stage.
I tried making a movie_clip with the same dimensions as the stage and naming it "stage_mc" and switching all references from "stage" to "stage_mc"... and that sort of works, but obviously not for:
stage.displayState = StageDisplayState.FULL_SCREEN;
Is there any way around this? Is there a way to recognize the stage in an external movieclip?
No, there's only one stage. In your case it will represent the parent SWF's stage.
But to get around your fullscreen problem you could still set the stage to fullscreen mode and then scale stage_mc to fill the parent SWF.

Away3D Context3D not available

I'm checking out Flash's 3D capabilities with Away3D, and I'm following the tutorial here. I've run into a major problem though. Everytime I run my project in the browser, I get this error:
Error #2044: Unhandled ErrorEvent:. text=Error #3702: Context3D not available.
I can't see where this error comes from, but it happens after my constructor function ends and before the ENTER_FRAME handler starts.
My code is like this:
package {
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.primitives.SphereGeometry;
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor="#000000", frameRate="60", width="1024", height="768")]
public class TestAway extends Sprite {
private var view:View3D;
public function TestAway() {
view=new View3D();
addChild(view);
var sphereGeometry:SphereGeometry=new SphereGeometry(350);
var sphereMaterial:ColorMaterial=new ColorMaterial(0xff0000);
var mesh:Mesh=new Mesh(sphereGeometry, sphereMaterial);
view.scene.addChild(mesh);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void {
view.render();
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
}
Now the wierd thing is, when I run it on my browser (FP 11.2), it doesn't work (gives that error), but I can run the swf from the desktop perfectly.
Also, the example file on the tutorial page runs perfectly. What setting is missing, and how can I fix it?
Well, it appears you need to set wmode as direct to make use of the 3D API.
While I had seen this bit of info, the html wrapper needs to be modified in 3 places for it to work on all configurations:
(1) In the javascript for swfObject
params.wmode = "direct";
(2) In the <object> tag
<param name="wmode" value="direct" />
and (3) in the <object> tag for IE
<param name="wmode" value="direct" />
To extend further helpful hints, if you are trying to open an application that uses Context3D in a new NativeWindow, you need to make sure that the you specify the renderMode in the NativeWindowInitOptions that gets passed into the NativeWindow. The render mode cannot change after the Native Window gets created.
// New window.
options = new NativeWindowInitOptions();
options.renderMode = "direct";
options.transparent = true;
options.systemChrome = NativeWindowSystemChrome.NONE;
nativeWindow = new NativeWindow( options );
I'm posting here hoping to help anyone with the same problem, but exporting to AIR.
Edit the app descriptor.xml and change the value to of rendermode to:
<renderMode>direct</renderMode>
Hope it helps

How to loop FLV seamlessly

I am playing looped FLVs in the "standard way":
netstream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
...
public function onStatus(item:Object):void {
if (item.info.code == "NetStream.Play.Stop") {
if (loop) netstream.seek(0);
}
When played through Flash CS 5.5 authoring tool (Test Movie or Debug Movie), the videos loop seamlessly. But! When played in the browser or standalone debug Flash player (both v.11.2.202.233) there is an abnormal pause of about 1 sec before the video "rewinds".
Is this a bug with the latest Flash player?
For People who have the same issue, try changing the aforementioned code to this:
public function onStatus(item:Object):void {
if (item.info.code == "NetStream.Buffer.Empty") {
if (loop) netstream.seek(0);
}
It will get rid of the flicker. If you listen to "NetStream.Play.Stop", it will cause a flicker.
You don't need to embed anything. This works just fine on IOS, Android and PC.
This is a known bug with Flash Player 11+ and AIR 3+. Bug report is here, and you should upvote & : https://bugbase.adobe.com/index.cfm?event=bug&id=3349340
Known workarounds that will create a seamless loop:
1) Embed the video in the SWF. Not ideal, and not possible in some cases.
2) Create dual NetSteam objects and switch between them. An example of the event fired when ns1, the first of two NetStreams objects, reaches it's end:
if (e.info.code == "NetStream.Play.Stop"){
vid.attachNetStream(ns2);
ns2.resume();
activeNs = ns2;
ns1.seek(0);
ns1.pause();
}
Replace ns1 with ns2 on the other event listener. A useless duplication of objects and handlers, but there you go.
3) Use AIR 2.x / Flash Player 10.x (not really a solution at all, except for Linux users)
We noticed this on the transition from Flash 10 to to Flash 11. Flash 10 loops seamlessly, but Flash 11 has a ~1 second stall when calling seek(0) from NetStream.Play.Stop.
Embedding the media in the SWF is not an option for us.
The following code provides a more seamless loop - still not perfect, but much better.
var mStream:NetStream;
var mDuration:Number;
...
addEventListener(Event.ENTER_FRAME, onEnterFrame);
...
function onEnterFrame(e:Event):void
{
if( mStream.time > (mDuration-0.05) )
{
if( mLooping )
{
mStream.seek(0);
}
}
}
function onMetaData(info:Object)
{
mDuration = info.duration;
}
Hope it helps.
I seem to have achieved this using an FLVPlayback component along with a few tips.
What's more, it's running seamlessly on desktop, iPhone 4S and 3GS! (via an AIR app)
_videoFLV = new FLVPlayback();
_videoFLV.fullScreenTakeOver = false;
_videoFLV.autoPlay = false;
_videoFLV.autoRewind = true;
_videoFLV.isLive = false;
_videoFLV.skin = null;
_videoFLV.y = 150;
_videoFLV.bufferTime = .1;
_videoFLV.width = 320;
_videoFLV.height = 320;
_videoFLV.addEventListener(MetadataEvent.CUE_POINT, video_cp_listener, false, 0, true);
_videoFLV.source = "includes/10sec.flv";
addChild(_videoFLV);
With the listener function...
function video_cp_listener(eventObject:MetadataEvent):void {
if (eventObject.info.name == "endpoint") {
_videoFLV.seek(0);
_videoFLV.play();
}
}
Importantly I think you must set the width and height to match your flv file. i.e. no scaling whatsoever.
The flv has a cue point named 'endpoint' added 1 frame before the end of the file (assuming your start and end frame are the same this will be required).I added this using Adobe Media Encoder.
The only way to loop an flv seamlessly is to embed inside the swf. It is converted to a MovieClip and you then handle it with play(), stop(), nextFrame(), prevFrame() etc.
When embedding in Flash Authoring tool (dragging flv file on stage), make sure that you select:
"Embed FLV in SWF..."
Symbol Type : "Movie clip"
All checked : "Place instance on stage", "Expand timeline...", "Include audio"