as3 video full screen mode - actionscript-3

I have created a video player, but need to add a button that, when clicked, puts the video into full-screen viewing mode. I don't want to scale everything on the stage - just the video. I can't seem to find how to do this - I thought it would be easy.

See if this works:
stage.displayState = StageDisplayState.FULL_SCREEN;
videoPlayer.x = 0;
videoPlayer.y = 0;
//save the width and height in temp vars
//for restoring them later.
videoPlayer.width = stage.fullScreenWidth;
videoPlayer.height = stage.fullScreenHeight;

My understanding is that you can only set the entire stage to full screen, not elements selectively, as you are effectively scaling up the stage object at the root of the display tree. The best way to accomplish the effect that you are looking for would be to arrange/hide/show any objects that you don't want to be visible in a FullScreenEvent.FULL_SCREEN event handler.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/FullScreenEvent.html
Also, a relevant tidbit from the Stage docs, displayState section:
The scaling behavior of the movie in full-screen mode is determined by the scaleMode setting (set using the Stage.scaleMode property or the SWF file's embed tag settings in the HTML file). If the scaleMode property is set to noScale while the application transitions to full-screen mode, the Stage width and height properties are updated, and the Stage the resize event.

Came across this problem recently and this worked like charm. So putting it up here in case it helps anyone.
Flex Client code:
private function startFullScreen(event:MouseEvent):void
{
videoHolder.removeChild(vid); //videoHolder is an spark VideoDisplay
Component
this.stage.addChild(vid);
this.stage.displayState = StageDisplayState.FULL_SCREEN;
oldWidth = vid.width; //store old values required while going back
oldHeight = vid.height;
vid.width = this.stage.width;
vid.height = this.stage.height;
this.stage.addEventListener(FullScreenEvent.FULL_SCREEN,fullScreenHandler);
}
}
/* handler for Fullscreen */
private function fullScreenHandler(event:FullScreenEvent):void
{
//This function is called when user presses Esc key
//on returning to normal state, add the video back
if(!event.fullScreen)
{
this.stage.removeChild(vid);
videoHolder.addChild(vid);
vid.width = oldWidth;
vid.height = oldHeight;
this.stage.removeEventListener(FullScreenEvent.FULL_SCREEN,fullScreenHandler )
}
}

If elements on the stage are scaling it sounds as though you're using the fullScreenRect property rather than simply instructing the stage object to go into fullscreen mode.
Amarghosh has the right approach, but it can be made more flexible by attaching a listener:
stage.addEventListener(Event.RESIZE, _onStageResize, false, 0, true);
stage.displayState = StageDisplayState.FULL_SCREEN;
private function _onStageResize(event:Event):void
{
if(stage.displayState == StageDisplayState.FULL_SCREEN)
{
// Proportionally resize your video to the stage's new dimensions
// i.e. set its height and width such that the aspect ratio is not distorted
}
else
{
// Restore the normal layout of your elements
}
}

To Enter Full Screen Mode
var fullScreenButton:Button = new Button();
...
addChild(fullScreenButton);
fullScreenButton.addEventListener(MouseEvent.CLICK, fullScreenButtonHandler);
...
private function fullScreenButtonHandler(event:MouseEvent)
{
var screenRectangle:Rectangle = new Rectangle(video.x, video.y, video.width, video.height);
stage.fullScreenSourceRect = screenRectangle;
stage.displayState = StageDisplayState.FULL_SCREEN;
}
To Leave Full Screen Mode
...
stage.displayState = StageDisplayState.NORMAL;
...
Note: You can also press escape.
Source: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS44B1892B-1668-4a80-8431-6BA0F1947766.html

Related

Can`t switch video from normal size

I imported the video into the project, that includes another videos in nomall size.
How to toggle the embedded video from normal predefined size to full screen and back with ActionScript 3?
I'm assuming your video is in a movie clip. So you could simply add a button to the stage and add a listener to it. Then the code within the listener would look like this:
boolFullScreen = !boolFullScreen
if (boolFullScreen == true)
{
mcVideo.width = stage.width;
mcVideo.height = stage.height;
}
else
{
mcVideo.width = 1920;
mcVideo.height = 1080;
}
The 1920x1080 is just an example.
Hope this helps

Unable to reference MovieClip inside Button AS3

I have this annoying issue that I hope someone might be able to help me with.
I have a mute button that I created and I have another movieclip inside of that button. All I want it to do is when I toggle the mute the movieclip inside will go to the according frame.
However, every time I try to call the movieclip inside of the button, this error comes up:
Access of possibly undefined property mcMuteToggle through a reference with static type flash.display:SimpleButton.
The instance name for the movieclip within is "mcMuteToggle".
Why not make movieClips that act like buttons?? Since I dont think actual button (simpleButton) types can deal with sub-MovieClips (especially if they too have code). Even if possible don't do it, I can predict a mess whereby Button does things it shouldn't do depending on what code you have in those MClips.
Try an alternate button method, just for a test... You didnt show any test code to work with so I will make assumptions..
1) Make a shape (rectangle?) and convert to MovieClip (or if all coded, then addchild shape to new MovieClip). Let's assume you called it mc_testBtn.
2) Make that MC clickable by coding mc_testBtn.buttonMode = true;
3) Add your mcMuteToggle inside the mc_testBtn
(or by code: mc_testBtn.addChild(mcMuteToggle);
Now you can try something like..
mc_testBtn.addEventListener (MouseEvent.CLICK, toggle_Mute );
function toggle_Mute (evt:MouseEvent) : void
{
if ( whatever condition )
{
mc_testBtn.mcMuteToggle.gotoAndStop(2); //go frame 2
}
else
{
mc_testBtn.mcMuteToggle.gotoAndStop(1); //go frame 1
}
}
This is likely due to strict mode. You can either disable it in the ActionScript settings dialog, access it with a different syntax myButton['mcMuteToggle'], or make a class for the symbol that includes a property mcMuteToggle.
You can also check to make sure the symbol is actually on the stage and that clip is actually in the button:
if('myButton' in root) {
// ...
}
if('mcMuteToggle' in myButton) {
// ...
}
i think u just overwrite that codes. You u can use something like this:
var soundOpen:Boolean = true;
var mySound:Sound = new Sound(new URLRequest("Whatever your sound is"));
var mySc:SoundChannel = new SoundChannel();
var mySt:SoundTransform = new SoundTransform();
mySc = mySound.play();
mcMuteToggle.addEventListener(MouseEvent.CLICK, muteOpenSound);
function muteOpenSound(e:MouseEvent):void
{
if(soundOpen == true)
{
mcMuteToggle.gotoAndStop(2);
/*on frame 2 u need to hold ur soundClose buton so ppl can see :)*/
soundOpen = false;
mySt.volume = 0;
mySc.soundTransfrom = st;
}
else
{
mcMuteToggle.gotoAndStop(1);
soundOpen = true;
mySt.volume = 1;
mySc.soundTransfrom = st;
}
}
This is working for me everytime. Hope u can use it well ;)

Optimize ItemRenderer For Flex Mobile Application

I made this class, which is an ItemRenderer class, used in a DataGroup ( mobile application ),
and I am not entirely sure if I did the right thing or not, my issues are :
Is there a better way to show the image, which is 80x80 and directly loaded from the server;
How to make the height of the row dynamic, I mean, depending on the height of the 3 StyleableTextFeild
Is this the right way to add the listener on the image, that will trigger a simple HTTPService,
Here is the functions from the class, Any help would be much appreciated !!
Image
Declared it as a simple image :
var logo:Image;
On override createChildren
logo = new Image();
addChild(logo);
And I added on set Data
logo.source = "http://192.168.0.15:3000/"+value.logo_thumb_url;
Size
override protected function measure():void {
measuredWidth = measuredMinWidth = stage.fullScreenWidth;
measuredHeight = measuredMinHeight = 100;
}
Listener
override public function set data(value:Object):void {
tel.text = String(value.Tel);
description.text = String(value.Descricao);
nome.text = String(value.Nome);
logo.addEventListener(MouseEvent.CLICK, function():void{
var service:HTTPService = new HTTPService();
service.url = value.targer;
service.method = "GET";
// setting headers and other variables ...
service.send();
});
}
You can use URLLoader or Loader for loading the image if you are planning to cache the image on the client side, if you cache the image, it wil help you not load the image again when the users scrolls through the list. (What you have done is Ok, but you will hit performance issues)
For variable row height, if Datagroup does not work, use List. find it here Flex 4: Setting Spark List height to its content height
There should be a buttonMode property for some items, make it buttonMode for the logo, for variable row height, find something related to wordWrap and variableRowHeight properties on the datagroup.
There are a few suggestions, what you have coded is good, but, instead of adding the listeners on set data, add it in creation complete, as it is more appropriate. Also, the event listeners has to be weak referenced, http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html#addEventListener()

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.

Flash: Stage.FullscreenInteractive -> Difference if class or 1st frame

example 1: 1st frame of my app
var screenBounds = Screen.mainScreen.bounds; //Bounds of current screen
var full:Sprite = new Sprite(); //Sprite Fullscreen
//Enter Fullscreen
function goFullScreen(e:Event = null) {
//myClass.goFullscreen();
full.graphics.clear();
full.graphics.beginFill(0xccff00);
full.graphics.drawRect(0,0,screenBounds.width, screenBounds.height);
full.graphics.endFill();
addChild(full);
this.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
example 2: a normal as class package
private var full:Sprite = new Sprite(); //Sprite to show fullscreen
private var screenBounds = Screen.mainScreen.bounds; //Bounds of current screen
public function favoritesFullscreen():void {
full.graphics.clear();
full.graphics.beginFill(0xccff00);
full.graphics.drawRect(0,0,screenBounds.width, screenBounds.height);
full.graphics.endFill();
addChild(full);
this.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
So, tell me WHERE IS THE DIFFERENCE?
I'm a macuser, you know, at the top the menubar and in my case the dock is aligned left
It's weird but example 1 does exactly what it should. It creates a fullscreen rectangle across the ENTIRE screen (from 0,0 to the right bottom)
However, example 2 kind of calculates the width of the top-menubar and the dock and starts the fullscreen rectangle a approx 40px from the left edge of the screen (dock) and 20px from the top (menubar)... i don't get why a external class acts different than as on the first frame.
??? thank you for your help!
I'm guessing it has to do with when the Screen.mainScreen.bounds are retrieved. On compile time, flash internally moves all frame code within functions in the DocumentClass and calls them after the stage has completly initialized. So, in the 1st example, you are retrieving the screenBounds after everything is initializated, but in the 2nd example you are doing it much earlier.
I guess waiting for the ADDED_TO_STAGE event would be enough. If it's not, the first ENTER_FRAME event dispatched should definitely work.