flash video gallery in flash cc and AS3 - actionscript-3

So i been trying to create to create a flash video gallery for my website but im getting an error on it even though the code should be correct
Below is the code i came up with
stop();
one.add Eventlistener(MouseEvent.CLICK,vid1);
two.add Eventlistener(MouseEvent.CLICK,vid2);
three.add Eventlistener(MouseEvent.CLICK,vid3);
four.add Eventlistener(MouseEvent.CLICK,vid4);
five.add Eventlistener(MouseEvent.CLICK,vid5);
function vid1(event:MouseEvent):void
{
vidPlayer.source ="flv/01.flv"
}
function vid2(event:MouseEvent):void
{
vidPlayer.source ="flv/02.flv"
}
function vid3(event:MouseEvent):void
{
vidPlayer.source ="flv/03.flv"
}
`enter code here`function vid4(event:MouseEvent):void
{
vidPlayer.source ="flv/04.flv"
}
function vid5(event:MouseEvent):void
{
vidPlayer.source ="flv/05.flv"
}
vidPlayer.playButton = player
vidPlayer.pauseButton = pauser
Does anyone have any idea on whats wrong with it ?

addEventlistener is a function, which will register an event listener object, and the name of a function should never contain spaces which is your error, so you should write :
one.addEventlistener(MouseEvent.CLICK,vid1);
two.addEventlistener(MouseEvent.CLICK,vid2);
three.addEventlistener(MouseEvent.CLICK,vid3);
four.addEventlistener(MouseEvent.CLICK,vid4);
five.addEventlistener(MouseEvent.CLICK,vid5);
Hope that can help.

Related

Flash Error #1009 for a Button

I'm new to AS3, and I keep getting Error #1009 when I try to add a button. From some reading I did I gather it is when I reference something I think exists but that really doesn't, except I have added a correct instance_name, and this did not happen for any of my other buttons.
Below is my code:
stop();
//buttons
Erhu_btn.addEventListener(MouseEvent.MOUSE_DOWN, Erhu_func);
Flute_btn.addEventListener(MouseEvent.MOUSE_DOWN, Flute_func);
Guzheng_btn.addEventListener(MouseEvent.MOUSE_DOWN, Guzheng_func);
Ruan_btn.addEventListener(MouseEvent.MOUSE_DOWN, Ruan_func);
Yangqin_btn.addEventListener(MouseEvent.MOUSE_DOWN, Yangqin_func);
Compose_btn.addEventListener(MouseEvent.MOUSE_DOWN, Compose_func);
Intro_btn.addEventListener(MouseEvent.MOUSE_DOWN, Intro_func);
//function definitions
function Erhu_func(event:MouseEvent):void {
gotoAndStop("Erhu");
}
function Flute_func(event:MouseEvent):void {
gotoAndStop("Flute");
}
function Guzheng_func(event:MouseEvent):void {
gotoAndStop("Guzheng");
}
function Ruan_func(event:MouseEvent):void {
gotoAndStop("Ruan");
}
function Yangqin_func(event:MouseEvent):void {
gotoAndStop("Yangqin");
}
function Compose_func(event:MouseEvent):void {
gotoAndStop("Compose");
}
function Intro_func(event:MouseEvent):void {
gotoAndStop("Intro");
}
All the buttons work except for the Intro_btn. I know it's probably a really simple mistake, but I can't figure it out, and I would really appreciate any light you could shed on my problem!

AS3 navigateToURL only works when testing in Flash CC

I've tried searching stackoverflow to find an answer to this question but so far haven't found anything.
I have a swf file with several movie clips on the stage. When I've managed to create an event where the movie clips swap out to a new movie clip when the user hovers. The problem that I am having is when you click that new movie clip it's supposed to open a URL in a browser window. That happens when I test the movie within Flash CC but when I test it in a browser nothing happens.
Any help for this would be greatly appreciated. I apologize if this question has been asked elsewhere on the site but, as I said, I did a search earlier and didn't find anything.
import flash.events.MouseEvent;
addEventListener(MouseEvent.MOUSE_OUT, gobackAnimation);
function gobackAnimation(event:MouseEvent):void
{
MovieClip(parent).gotoAndStop(1)
}
addEventListener(MouseEvent.CLICK, openURL);
function openURL(event:MouseEvent):void
{
ExternalInterface.call("open", "URL I'm trying to open");
MovieClip(parent).gotoAndStop(1)
}
To open a URL you have to use the navigateToURL function as documented here.
It appears that you are using the following code to trigger a URL to open:
function openURL(event:MouseEvent):void
{
ExternalInterface.call("open", "URL I'm trying to open");
MovieClip(parent).gotoAndStop(1)
}
However, I don't know where or what this ExternalInterface is and how the call function is built.
If you want to open a URL though, you should be doing something along the following lines:
function openURL(event:MouseEvent):void
{
var myURL:String = "http://your.url.goes/here"; // set your url here
var window:String = "_blank"; // you can set this to be whatever you need based on how you want the window opened
var request:URLRequest = new URLRequest(myURL);
request.data = variables;
try {
navigateToURL(request,window);
}
catch (e:Error) {
// handle error here
}
MovieClip(parent).gotoAndStop(1)
}

AS3: Call function does not work in browser

Here I have AS3 to for uploading recorded sound file to server. When I test it in Flash it works properly (record sound and upload it and goes to next frame) , but in browser it doesn't work. It seems can't call myUpload but I don't why? Is it should be mouse event? Thanks.
function VOCWordToYourMp3()
{
setTimeout(startRecording,3000);
recorder.addEventListener(RecordingEvent.RECORDING, onRecording);
recorder.addEventListener(Event.COMPLETE, onRecordComplete);
}
function startRecording()
{
if (! recording)
{
recorder.record();
}
else if (recording)
{
recorder.stop();
recording = false;
}
}
function onRecording(e:RecordingEvent)
{
//
}
function onRecordComplete(e:Event):void
{
//
}
function renderWav(src, convertToMp3 = false)
{
//
function handleRenderTimer(e:TimerEvent)
{
//
}
function finishRender()
{
//
}
}
function makeIntoMp3(wav)
{
wav.position = 0;
mp3Encoder = new ShineMP3Encoder(wav);
mp3Encoder.addEventListener(Event.COMPLETE, mp3EncodeComplete);
mp3Encoder.addEventListener(ProgressEvent.PROGRESS, mp3EncodeProgress);
mp3Encoder.start();
function mp3EncodeProgress(e:ProgressEvent):void
{
//
}
function mp3EncodeComplete(e: Event):void
{
myUpload('sound1',mp3Encoder.mp3Data);
}
}
function myUpload(namefile:String,sba: ByteArray):void
{
//upload code
}
Update:
In Flash Player 10 and Actionscript 3.0, all the calls to URLLoader must be in the same callstack.
http://helpx.adobe.com/flash-player/kb/user-interaction-required-upload-download.html
What is same callstack mean?
I recommend using something like Vizzy: https://code.google.com/p/flash-tracer/ to debug your swf in the browser. You can put trace statements into the onRecordComplete() and myUpload() functions, etc, to see how far the code is getting, and to see if you are getting any new errors. You may have some kind of security sandbox error because you are running in the browser. Being able to see what that error is will help you figure out what to do next.
To use Vizzy, you need to have the debug player running in your browser, and to configure the right path to your log file. This is sometimes a little bit tricky, so I'll give you some tips:
Add a file to your home directory called mm.cfg, and populate it with these settings:
ErrorReportingEnable=1
AS3Verbose=0
TraceOutputFileEnable=1
AS3Trace=0
TraceOutputBuffered=0
AS3StaticProfile=0
Then in Vizzy you have to set up the path to the log. On my windows 7 machine it is here:
C:\Users\MyUserName\AppData\Roaming\Macromedia\Flash Player\Logs\flashlog.txt
It may be different depending on your operating system.
Good luck, and report back if you Vizzy gives you any new information.

How do I give a function to only the second frame of a movie-clip? (AS3)

I want to create a function that only allows the second frame of a movie clip to allow navigation of SWF. The "2button" is the original movie-clip while the "unlock2" is a different movie-clip on the second frame of "2button"
I tried:
//test
public function open(){
2button.unlock2.addEventListener(MouseEvent.CLICK,clickjump2);
function clickjump2(event:MouseEvent) {
gotoAndStop("play2");
}
}
Any suggestions or improvements to this would be greatly appreciated :D!
try this:
function open():void
{
2button.unlock2.addEventListener(MouseEvent.CLICK,clickjump2);
}
function clickjump2(event:MouseEvent):void
{
//check if 2button is at frame 2
if (2button.currentframe==2)
{
gotoAndStop("play2");
}
}
ps: as Versper pointed out, dont start names with numbers

Flash CS5 Actionscript 3.0 Go to Next Frame and Play Code

I am coding a simple movie timeline in Flash CS5 actionscript 3.0. I have all my buttons working except for the Play button which I would like to code to say "go to next frame and play". Here is my current actionscript can anyone help me to find the correct code?
fastforwardBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);
function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(4025);
}
stop();
gotoStopBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_2);
function fl_ClickToGoToAndStopAtFrame_2(event:MouseEvent):void
{
gotoAndStop(1);
}
gotoPlayBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);
function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
{
gotoAndPlay(1);
}
stopBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame_2);
function fl_ClickToGoToNextFrame_2(event:MouseEvent):void
{
nextFrame();
}
playBtn.on (release) ;{
_root.gotoAndPlay(_currentframe+1);
}
playBtn.addEventListener(MouseEvent.CLICK, fl_Click_Play);
function fl_Click_Play(event:MouseEvent):void
{
MovieClip(root).play();
}
should work, if you have a simple fla. And if that doesn't seem to work, you may need something like this to target the right path:
MovieClip(this.parent).play();
Without knowing your fla structure, its just a guess ;)
also = _root is AS2, and always targets _level0. This is changed in AS3 to just "root", and targets the timeline of the topmost displayObjectContainer.