I have a flash musicplayer, that is very simple by itself. it has one button, Start/Stop.
The player itself is in footer.
The Problem: when the page loads music won't start (FLASH player won't play) before you don't see it on the page, I mean, when the screen is small by resolution, you don't see the footer - and music doesn't start. when you scroll down to footer (when you see the player) it starts playing.
How should I do that no matter if you see the player or not - the player starts playing.
THANKSSS!!!!
Do play & stop buttons in JavaScript for the 1px square player in position fixed on the top.
in javascript :
str = "stop";
function appel(str) {
document.getElementById("id_flash").echo(str);
}
in as3 :
import flash.external.*;
function echo(str:String):Void {
switch(str) {
case "play":
sound.play();
break;
case "stop":
sound.stop();
break;
}
}
ExternalInterface.addCallback("echo", null, echo);
Related
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
need an assistance to setup a Scroll To Play mode for JWPlayer. Anyone can help?
Basically, I need a video to start only when a user scrolled down the page, where the video player is embed. Autoplay or Click To Play functions do not suit me here. Unfortunately, there is no built in functionality in the CMS of JWPlayer for Scroll To Play settings.
Any advice on this will help me a lot!
Thanks in advance!
You can start the player when the player is visible. Something like:
scrollView.getViewTreeObserver().addOnScrollChangedListener(
new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (player.getLocalVisibleRect(scrollBounds)) {
// if player is visible (even a single pixel)
if (player.getState() != PLAYING) {
player.play(true);
}
} else {
// if player is not visible (even a single pixel)
if (player.getState() == PLAYING) {
player.pause(true);
}
}
}
})
```
I have made a simple drag and match game for kids.
I used setchildindex for movie clips to be dragged but when I click next button and go to another frame but movie clips are remaining in the same stage. What should i do?
Here is my code I used: (drag_1, this.numChildren0);.
When I reload it's not working.
drag_1.buttonMode = true;
drag_1.addEventListener(MouseEvent.MOUSE_UP, dropMe_1);
drag_1.addEventListener(MouseEvent.MOUSE_DOWN, dragMe_1);
var back_1X:Number = back_1.x;
var back_1Y:Number = back_1.y;
var hit_2X:Number = hit_2.x;
var hit_2Y:Number = hit_2.y;
function dragMe_1(event:MouseEvent)
{
drag_1.startDrag()
setChildIndex(drag_1, this.numChildren-1);
}
function dropMe_1(event:MouseEvent)
{
drag_1.stopDrag();
if(drag_1.hitTestObject(drop_2))
{
TweenMax.to(drag_1, 0.5, {
x:hit_2X,
y:hit_2Y,
ease:Cubic.easeOut
});
drag_1.mouseEnabled = false;
SoundMixer.stopAll();
}
else
{
TweenMax.to(drag_1, 0.5,
{
x:back_1X,
y:back_1Y,
ease:Bounce.easeOut
});
}
}
You need to remove the MovieClips using removeChild().
Now, why do you need to do that here? Well, this is one of those odd problems you get when you mix the timeline with code. When you place a symbol on the timeline keyframe, the Flash Player will instantiate that symbol when it reaches that frame. After that, any frame on the timeline that updates the symbol (tweens, effects, etc) will do just that, and any frame that lacks the symbol will remove it. However, the Flash Player is very picky about identifying that symbol on each frame of the timeline. When you move it using setChildIndex you are basically breaking the timeline link, and the Flash Player no longer identifies it and removes it based on the keyframes. You'll also find that if you revisit a keyframe that had that symbol, the Flash Player will instantiate a second one regardless if the one you moved is still there. As you can see, it can get pretty messy.
Making a custom AS3 preloader, I noticed that when my SWF is executed locally (file:///) the preloader gets stuck in the loading screen when previewed in a web browser like Chrome.
When executed from a remote server or through the standalone Flash Player, then it works. I noticed other SWF that have preloaders do not have this issue. What I need to change?
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, preloaderProgress);
function preloaderProgress(event:ProgressEvent):void {
var loadedPercent:Number = event.bytesLoaded/event.bytesTotal*100;
if (loadedPercent == 100){
this.gotoAndStop(2);
}
}
Loading locally goes very fast. Not only you should check if the file is completely loaded using the Event.COMPLETE and not the ProgessEvent but you should also make sure to register your listeners before actually calling load or the file might end up completely loaded before you register your listeners.
Following the example at http://stephenscholtz.com/201110/single-movie-flash-preloading-as3
It seems that there was no ProgressEvent.COMPLETE, but there is a Event.COMPLETE instead, a bit confusing.
I changed my code to the following, (also including some tweaks for right click menu to prohibit the user from right clicking and pressing Play before movie has loaded and such)
//Initialize any variables
var loadedPercent:Number = 0;
//Remove all items from right click Flash Player menu (except Quality, and the mandatory About... & Settings...)
var cxMenu:ContextMenu = new ContextMenu();
cxMenu.hideBuiltInItems();
cxMenu.builtInItems.quality = true;
this.contextMenu = cxMenu;
/* or disable right click menu completely (Flash Player 11.2.202.228 and over) */
/* this.addEventListener(MouseEvent.RIGHT_CLICK, onMouseRightClick);
function onMouseRightClick(event:MouseEvent)
{
return false;
} */
//Disable shortcut keys and window menubar when played from desktop Standalone Flash Player app
if (Capabilities.playerType == "StandAlone" || Capabilities.playerType == "External") {
fscommand("showmenu", "false");
fscommand("trapallkeys", "true");
}
/* Preloader: begin */
//Update loading bar and percent text as SWF loads
function onProgress(e:Event) {
//Get the amount of bytes that have been loaded / bytes total to load
loadedPercent = this.loaderInfo.bytesLoaded/this.loaderInfo.bytesTotal*100;
//Update the text of _preloaderProgress movieclip
_preloaderProgress.text = int(loadedPercent)+"%";
//Update the _preloaderBar amount by scaling horizontally as it loads
_preloaderBar.scaleX = loadedPercent/100;
}
//Go to next frame after everything loads
function init(e:Event) {
gotoAndStop(2);
}
//Attach the events to the stage
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, init);
/* Preloader: end */
//Stop to 1st frame and wait until it is loaded
stop();
This will allow the movie to play both remotely and locally with no problems.
I've got a Flash CS6 FLA with an instance of the FLVPlayback component (2.5.0.26) and an instance of the Progress Bar component on the stage, loading an external FLV.
I'm trying to preload a specific percentage of video before playing.
When hosted on a server, the video launches and plays as expected 80% of the time, but 20% of the time the video gets stuck in a buffering state on launch (blank area where video should be), and I can't get it to play through AS3 or by clicking the play button on the skin controls. Oddly, if I refresh the browser when it's stuck I see a glimpse of the video before the page reloads and then plays the video as expected.
I've tested on a Mac (Lion) in Chrome, Firefox, and Safari and had the same results.
The video problem gets worse if I limit my bandwidth using SpeedLimit.
Any suggestions would be greatly appreciated.
Code:
public class SimpleVideoLoad extends MovieClip {
var isLoaded:Boolean = false;
public function SimpleVideoLoad() {
// constructor code
loadVideo();
}
function loadVideo():void
{
my_FLVPlybk.x = 0;
my_FLVPlybk.y = 0;
my_FLVPlybk.width = 743;
my_FLVPlybk.height = 300;
my_FLVPlybk.source = "CARSdotCOM_OLD.flv";
//preloader component
pb.source = my_FLVPlybk;
pb.addEventListener(ProgressEvent.PROGRESS, progressHandlerPB);
}
//progress bar component
function progressHandlerPB(event:ProgressEvent):void {
var percentOfVideoLoaded = pb.percentComplete;
if (percentOfVideoLoaded>10 && isLoaded == false){
isLoaded = true;
my_FLVPlybk.play();
}
}
}