Can`t switch video from normal size - actionscript-3

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

Related

How to use MuteButton video component?

I need to create a button, which plays/stops background music in my flash game. I could use Button component with custom images, but I found MuteButton component which appears to have everything that I need, including images. The problem is that I don't know how to set up MuteButton and is that even possible to use without using FLVPlayback component on first place?
If you want to enable mute button in single button you can use
var volumeOn:Boolean = true;
var globalVolume:Sound = new Sound();
btnSoundOff.onRelease = function():Void {
if (volumeOn) {
globalVolume.setVolume(0);
} else {
globalVolume.setVolume(100);
}
volumeOn = !volumeOn;
}

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 ;)

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.

Play sound at certain playProgress or videoTime with greensock?

I'm using greensock LoaderMax to load video files and sound files. I've copied as much code as is available to me. A video (s9) is playing and at a certain percentage through the video, I need to play another sound.
if(s9.playProgress > .1) // This is what I can't get to work
{
s12_sound.playSound(); //This sound won't play at .1 playProgress
}
s9.content.visible = true;
s9.playVideo();
stop();
s9.addEventListener(VideoLoader.VIDEO_COMPLETE, play_s9_loop); //This plays a video once s9 is done.
function play_s9_loop(event:Event):void
{
s9.content.visible = false;
s9_loop.content.visible = true;
s9_loop.playVideo();
}
I'm guessing you just can't do an if() on playProgress? Furthermore, I suck at AS3.
You should be able to just listen for the INIT event on the video (which typically means it has loaded enough to determine the duration of the video) and then add an AS cue point.
//...after you create your VideoLoader...
myVideoLoader.addEventListener(LoaderEvent.INIT, initHandler);
myVideoLoader.load();
function initHandler(event:LoaderEvent):void {
myVideoLoader.addASCuePoint( myVideoLoader.duration * 0.1, "myLabel" );
myVideoLoader.addEventListener(VideoLoader.VIDEO_CUE_POINT, cuePointHandler);
}
function cuePointHandler(event:LoaderEvent):void {
trace("Hit the cue point " + event.data.name);
s12_sound.playSound();
}
Also make sure that you preload that s12_sound so that it's ready to play when you need it. Otherwise, you can call playSound() all you want and it ain't gonna happen :)
I haven't used this class before but after reading the docs it looks like you can do something like this:
http://www.greensock.com/as/docs/tween/com/greensock/loading/VideoLoader.html
var mid:Number = s9_loop.duration/2; //get the midpoint using the duration property
s9_loop.addASCuePoint(mid, "middle") //using addASCubePoint to add a cuepoint to the midpoint of the video
s9_loop.addEventListener(VideoLoader.VIDEO_CUE_POINT, handleMidpoint); //listen for the cuepoint
Inside the handler function
protected function handleMidpoint(e:Event):void{
//play your sound
}

as3 video full screen mode

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