How to use MuteButton video component? - actionscript-3

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

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

Making multiple objects draggable

I have about 50 symbols that I want to make draggable. Nothing fancy, just the ability to click it and drag it to a different location.
I found as3 code for doing so but when I paste it into my file it gives me errors:
**Error** Scene=Scene 1, layer=Units, frame=1:Line 9: The class or interface 'MouseEvent' could not be loaded.
function mouseDownHandler(evt:MouseEvent):void {
That code is:
// Register mouse event functions
fighter_uk.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
fighter_uk.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
fighter_uk.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
fighter_uk.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
obj.stopDrag();
}
I'm using flash pro 8, so I tried finding as2 code but couldn't find it.
Also, is there an 'easy' way to code all 50 objects?
I think you're trying to compile AS3 code with AS2 compiler. Try changing your compilation settings to target AS3.
Also you may need to include the class import at the top of your code:
import flash.events.MouseEvent;
To drag 50 objects, add them all on the same container sprite and add the listener to the container sprite only:
var holder:Sprite = new Sprite();
for ( var i:int = 0, l:int = 50; i < l; i++ ) {
var dragee:YOUR_CUSTOM_OBJECT = new YOUR_CUSTOM_OBJECT();
holder.addChild(dragee);
}
addChild(holder);
holder.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
holder.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
holder.addEventListener(Event.MOUSE_LEAVE, mouseUpHandler);
var currentDragee:YOUR_CUSTOM_OBJECT = null;
function mouseDownHandler(evt:MouseEvent):void {
currentDragee = evt.target as YOUR_CUSTOM_OBJECT;
if ( currentDragee !== null ) {
currentDragee.startDrag();
holder.addChild(currentDragee); // bring current to front position
}
}
function mouseUpHandler(evt:Event):void {
if ( currentDragee !== null ) currentDragee.stopDrag();
currentDragee = null;
}
YOUR_CUSTOM_OBJECT being the object class you need to drag. Hope it helps!
This page seems to have the answers you are looking for (AS2 drag and drop). If you've already seen it, you'll need to explain why it's not good enough for your needs.
If you want to drag/drop multiple instances in AS2, you can still add the code to the movieClip symbol, export it from the library and load the instances up using attachMovie (all 50 of them). If they are all different, then attach the code as necessary to the clips themselves, or to some function elsewhere that will capture all the clicks and decide what was clicked. This is all very doable in AS2.
Remember you can use your onClipEvent(load) function to set up a lot of the initial lifting.
Here's a sample I made in AS2 for making a node tree. It's all draggable (mouse drag) and zoomable (with mouse Wheel). You can add nodes by clicking on the little down arrow in the node box. Each node is listening for the mouse.
You'll want to look at this section for the most part:
// Enable drag on button press
on (press)
{
startDrag(this);
}
// Stop the drag on release of mouse button
on (release)
{
stopDrag();
}
Besides this, I'm not really sure how your setup looks, so I hope this helps get the ball rolling. (Check the link, there's lots of little gems in there).
Flash Professional 8 only supports ActionScript 2 & 1
You can follow this official URL and learn how to do that in ActionScript 2, but I extremely recommend you to work with ActionScript 3.

Disable Mouse Blocker in Starling

How to block all mouse touch input into my Actionscript 3 Starling game?
Basically I need to ignore all touch events for a set period of time.
If you don't want an object to be touchable, you can disable the "touchable" property. When it's disabled, neither the object nor its children will receive any more touch events.
There is no need to add new display object to prevent touches.
this.touchable = false;
Developed a quick solution! Basically create a Quad that is the size of your screen, and add it to the front most layer.
Add to init() function of front most layer file:
Starling.current.addEventListener('TOUCH_BLOCKER_ENABLE', touchBlockerEnable);
Starling.current.addEventListener('TOUCH_BLOCKER_DISABLE', touchBlockerDisable);
Then define these functions:
private function touchBlockerEnable(e:Event):void
{
if(!_quad)
{
_quad = new Quad(Starling.current.stage.width,Starling.current.stage.height,0xFFE6E6);
_quad.x = 0;
_quad.y = 0;
_quad.alpha = 0.1;
addChild(_quad);
}
}
private function touchBlockerDisable(e:Event):void
{
if(_quad)
{
removeChild(_quad);
_quad = null;
}
}
Call this function to activate the Touch Blocker:
Starling.current.dispatchEvent(new Event('TOUCH_BLOCKER_ENABLE'));

is there a way to control the FLVPlayback component's volume using the slider component in Flash?

I was wondering if there was a way to get the sound from a FLVPlayback component and manipulate it with using a custom volume slider?
Within my Actionscript I currently have this code which enables me to control the volume of a MP3:
import fl.events.SliderEvent;
var mysong = new music();
var myChannel:SoundChannel = new SoundChannel();
var myTransform = new SoundTransform();
myChannel = mysong.play(0,10);
slider.addEventListener(SliderEvent.THUMB_DRAG, changeVolume);
function changeVolume(event:SliderEvent):void{
myTransform.volume=slider.value;
myChannel.soundTransform = myTransform;
}
But Instead of using the MP3 for sound, is there a way to use an FLV's sound instead?
Have a look at this example. It shows how to do what you are asking.
Basically you need to create the FLVPlayback component either using the following code or just within the flash visual layout editor.
var flvPlayback:FLVPlayback = new FLVPlayback();
Once you have your player you can just use its volume property inside of an event listener like the following:
function slider_change(evt:SliderEvent):void {
flvPlayback.volume = evt.value;
}
Set your slider component to trigger that event listener function and you should be good to go.
So basically it looks to me like the key part you are missing is that the FLVPlayback objects have an actual voume property that you can set. Do it the same way you have your mp3 player set up but change the volume property of the actual FLVPlayback object.