Controlling Sound / Volume - actionscript-3

I added a sound to the Flash Professional CC library and had the program convert it to MP3. If I create a layer and drag-and-drop the sound onto the stage the sound plays fine (even after passing it through Swiffy), however that is all I am able to do so far.
I need some way to control when the sound plays as well as volume. I tried the giving the sound a class (Sound Properties -> ActionScript -> Export for ActionScript and assigned a class name mySound).
Then added this ActionScript to the first frame:
var myAudio:Sound = new mySound();
myAudio.play();
However, after passing it through Swiffy, I get the following errors:
The ActionScript class flash.media.Sound is not supported.
The ActionScript method flash.media.Sound.play() is not supported.
So I can't use the base Sound class in Flash? Is there another base class that can be used and is it compatible with the flash.media.Sound class? Is there some other way to control playback so that it can be played at a specific time -- such as on mouse roll-over or when something is clicked?

You could try using SoundJS. BTW, Flash Pro CC does have an HTML Canvas document type that uses CreateJS (which SoundJS is part of) under the hood. It won't convert AS3 to JS, though, you have to write the JS code yourself.

Related

Seekbar for mp3 player in Actionscript 3.0 Flash CS-6

I'm trying to create a music player in Flash CS6. I'm new to Flash. I have created the play/pause/volume buttons. I have also been able to extract the mp3 information using the id3 tags. So i have the song duration. I now need to create a seekbar/progress bar. I have taken the progress bar from the components, but do not understand how to code it now. Please help!
According to the reference on Sound.play():
public function play(startTime:Number = 0, loops:int = 0, sndTransform:flash.media:SoundTransform = null):SoundChannel
where the first argument is
startTime:Number (default = 0)//The initial position in milliseconds at which playback should start.
so you can call
channel.stop();
channel = sound.play(offset);
There is an example in the reference. Hope this helps.
You can get some idea using my audio player on my Github page.Also it's developed using flash CS6 and ActionScript 3.0. Use it, change it and develop your future with ActionScript .

AS3 Starling: Trying to add Video

I'm a total AS3 / Starling newbie, but I'm trying to (programmatically) add an FLV video file to the 'background' of what is essentially a splash screen.
Example code I have found online basically distills to...
var v:Video = new Video(100, 100);
this.addChild(v);
This works in the top-level class that extends flash.display.Sprite, however my Game class (that extends starling.display.Spite) fails, complaining of an "Implicit coercion of a value of type Video to an unrelated type DisplayObject."
Strangely enough, the signature of the addChild function on the Starling Sprite class is the same as that of the Flash Sprite class.
So basically the question is: why do I seem to be unable to add a Video object as a child to a Starling Sprite class (but successfully to a Flash Sprite class)?
I'm sure the answer is ridiculously simple... please let me know if I need to add more code or anything. Or if what I'm doing is totally the wrong way.
Or you could add the video to the Flash layer which sits above Starling:
Starling.current.nativeOverlay.addChild(v);
and
Starling.current.nativeOverlay.removeChild(v);
Bare in mind you are not using Starling GPU drawing with this though.
This is because the Starling framework was designed to mimic the regular Flash DisplayList (not completely recreating all the features though). Concretely, you are trying to pass a reference to an object of type starling.display.DisplayObject instead of flash.display.DisplayObject, which gives the appropriate error.
In order to play a video with Starling, you could upload each frame of the movie to a texture. Have a look at this topic on Starling's forum.

Flash CS6 Importing sounds

I'm working on a Flash project in CS6 and need to import a sound to my library but I'm having endless problems with it. I'm using external files in Actionscript 3.0 (e.g. I cannot do a URLRequest as it won't work externally, need to import)
I'm using a sound that should work, some errors go in that it can't be over 160kbps, this is only at 32 in the MP3 file. I converted it to an AIFF, no success, a WAV? no success.
If it's an MP3 I simply get "Couldn't import "
If it's a AIFF or WAV I get "One or more files were not imported because there was a problem reading them"
Adobe suggest you need to files under 160kbps, all are set at 32kbps to be safe.
Another suggestion said you needed Quicktime 7.7.1 (or newer) and iTunes 10.5.5.3 (or newer) for this to work with an MP3 file. I have Quick 7.7.3 and iTunes 11.0 so I really have no idea of the problem.
Can anyone help, this project needs finished quickly.
Thanks.
John.
Could be to do with bitrates.
I was running into issues with some mp3 files that I had converted from wav using Audacity. It was a specific few that wouldn't work, so I went back to Audacity and compared the working-mp3-yielding wavs to the non-working. I noticed that the working wavs had a bitrate of 44100Hz the non-working had 48000Hz. Setting the project rate ( bottom left corner ) to 44100Hz before exporting yielded mp3s that imported into flash with no problem.
In short:
48000 Hz = naughty
44100 Hz = nice
This is a weird problem here's a simple code snippet that load and play an MP3 sound AS3 doesn't support WAV natively :
//sound object
var sound:Sound = new Sound(new URLRequest("music.mp3"))
var soundChannel:SoundChannel = sound.play();
Hope this help :)
This post is kind of old but I thought I would post an answer after running into the same problem. I am also using Flash Pro in CS6. What you want to do is to embed the sound into your FLA so that when your SWF is compiled the sound will go with it. Khaled's answer is great but this issue needs a little more TLC.
What worked for me was to get an application that edits sound clips. I downloaded the open source 'Audacity.' In the bottom left corner of Audacity you can edit the project rate. Take it down to about 1600 or lower. Then save the project and export the sound as an mp3.
Finally, make sure that your sound clip is in the same folder as your FLA. Import into your FLA (this should work now) and export your sound for actionscript by right clicking the sound in the library, going to properties. Change the name of the class to whatever you want (at least get rid of the '.mp3' from the class name).
Then use the following code (which is different from the typical URL loader for sounds):
//sound is a constructor variable under your document class
public class DocumentClass extends MovieClip
{
var yourSound:yourSoundClass;
public function DocumentClass()
{
init();
}
function init():void
{
yourSound = new yourSoundClass();
}
}
Then play your sound by using yourSound.play(); This technique will embed your sound within the SWF so it will go wherever the SWF goes. I hope that helps anyone who runs into this.

Load as3 into as2 work only on _root

i made a simple test example in as2. This contains two buttons with the following handlers.
_root:
on (release)
{
this.loadMovie("AS3.swf");
}
_root.test.testmc:
on (release)
{
test.testmc.loadMovie("AS3.swf");
}
The AS3.swf is a video player(using youtube as3 api). If i load it into _root it works, but if i want to load it into any other place it doesn't. I searched and found this from adobe:
"SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0. This means that SWF files authored in Flash 8 or Flex Builder 1.5 or earlier versions cannot load ActionScript 3.0 SWF files.
The only exception to this rule is that an ActionScript 2.0 SWF file can replace itself with an ActionScript 3.0 SWF file, as long as the ActionScript 2.0 SWF file hasn't previously loaded anything into any of its levels. An ActionScript 2.0 SWF file can do this through a call to loadMovieNum(), passing a value of 0 to the level parameter."
Is the "_root part" of my code working because of the above "exception rule"? I am new to flash(yeah you could ask why i started with as2, unfortunately not my choice...) and i wonder if my thinking is right. Also if there is any sort of workaround(other than rewrite everything in AS3), let me know(maybe use of localconnection?).
Try this:
on root of as2:
test.testmc.loadMovie("AS3.swf");
or in the mc u want the as3 player:
this.loadMovie("AS3.swf");
Your second code is calling test.testmc.test.testmc because it is already placed in the "testmc" so you dont need to reference it with the full path. It's recommended that you use relative paths for things like this.
So, inside the mc testmc you just need to do this.loadmovie instead of searching for test.testmc INSIDE testmc.
Hope that was what you're looking for.

Flash AS3 error when importing 3D-tweened movieclip

I've been working on an AS3 application and it's nearing completion. At the same time, one of the designers I work with has been building a movieclip in a separate .fla that acts as an intro animation to the application. The intro uses the 3D motion tweening capabilities of Flash CS4 / Player 10, and runs fine in the .fla in which it was built.
The problem is that when I import the movieclip into the main .fla for the application, when I dynamically instantiate the movieclip and add it to the stage, I get a barrage of the following runtime error:
ReferenceError: Error #1069: Property null not found on fl.motion.KeyframeBase and there is no default value.
at fl.motion::KeyframeBase/getValue()
at fl.motion::MotionBase/getValue()
at fl.motion::Animator3D/setTime3D()
at fl.motion::AnimatorBase/set time()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorBase$/parentEnterFrameHandler()
I'm guessing just based on the number of errors like this that I receive that there's one per keyframe in the tweening movieclip. I've checked to ensure that the Flash publish settings are identical across the two .fla files, and although the stage sizes differ slightly, I don't think that's the issue here. I've also googled the issue and found nothing but but this lonely thread on kirupa.
Any thoughts?
Okay--turns out the problem was that we had a local version of the fl.motion package in the Actionscript source paths that was out of date. Now everything's tweening along happily!
As far as I know you once you apply a 3D Motion Tween to a clip, you can no longer modify it by actionscript.
I'd suggest either copying the clip, without the tween, so you can access and modify it via actionscript, as for the animation, maybe go for Copy Motion as Actionscript 3.0. It will spit out a nasty looking bulk of code. The alternative is to 'redo' the animation using something like TweenLite which has nicer syntax. You would select the motion tween, give it an instance then use instance.motion.keyframes to loop through the keyframes and get the position and rotation values for example.
It's not as ideal as it should be :(
Have a look at the flashthusiast.com website for more insights on the new tweens and how to work with them.
Goodluck,
George