Converting AS3 to AS2 - actionscript-3

I have this problem. Have a banner which is code with AS3, and our system only displays banners up to Flash Player 9. But Flash Player 9 does not support AS3 . So is there a way to do it on the easy way? Or I have to rewrite it on AS2 ? Here is the code.
import flash.events.Event;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
cierre.gotoAndStop(1);
SoundMixer.soundTransform = new SoundTransform(0);
video_player.autoPlay = true;
video_player.source = "video_500x374.f4v";
video_player.addEventListener(Event.COMPLETE, finVideo);
stop();
b2_btn.buttonMode = true;
buttonclose.addEventListener(MouseEvent.CLICK,buttoncl);
function buttoncl(e:Event):void{
video_player.stop();
this.gotoAndStop(1);
}
var paramList:Object = this.root.loaderInfo.parameters;
b2_btn.addEventListener(MouseEvent.CLICK, openURL);
function openURL(evtObj:MouseEvent):void {
var request:URLRequest = new URLRequest(paramList["clickTag"]);
navigateToURL(request, "_blank");
}
function aBanner1(e:Event):void{
video_player.stop();
this.gotoAndStop(1);
}
function finVideo(e:Event):void{
video_player.stop();
cierre.play();
}
function setMute(vol) {
var sTransform:SoundTransform = new SoundTransform (0,1);
sTransform.volume = vol;
SoundMixer.soundTransform = sTransform;
}
var Mute:Boolean = false;
mutebutton.addEventListener (MouseEvent.CLICK,toggleMuteBtn);
function toggleMuteBtn (event:Event) {
if(Mute) {
Mute = false;
setMute(0);
}else{
Mute = true;
setMute(1);
}
}

You need to use the AS2 FLV Playback component. You should start with a clean new AS2 fla and start copying everything over except the components stuff.

Related

How to successfully unload a swf, and go to parent swf, after pressing the exit button

Using a code snippet in as3 flash, but struggling for it to actually work:
I would like to unload the child SWF (which is a video) and go back into the parent SWF (a video selection page). Tried so many different ways and need a quick and easy solution. Thanks.
Below does not seem to work...
exit_btn.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import fl.display.ProLoader;
var fl_ProLoader:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad:Boolean = true;
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
fl_ProLoader.unload();
removeChild(fl_ProLoader);
fl_ProLoader = null;
}
I use this code it's tested
import flash.filesystem.*;
import flash.events.MouseEvent;
import flash.net.*;
import flash.events.*;
var _file: File;
_file = File.documentsDirectory.resolvePath("./Directory to swf file/mySwf.swf");
if (_file.exists) {
trace("SWF loading ...........");
displayingSWF(_file.nativePath)
} else {
trace("the file doesn't exit");
}
//////////////// DIsplay the SWF story file //////////////////
var mLoader: Loader ;
function displayingSWF(lnk) {
var inFileStream: FileStream = new FileStream();
inFileStream.open(_file, FileMode.READ);
var swfBytes: ByteArray = new ByteArray();
inFileStream.readBytes(swfBytes);
inFileStream.close();
mLoader = new Loader();
var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loaderContext.allowCodeImport = true;
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoadComplete);
mLoader.loadBytes(swfBytes, loaderContext);
}
function onSwfLoadComplete(e: Event): void {
mLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoadComplete);
addChild(mLoader);
}
exit_btn.addEventListener(MouseEvent.CLICK, dimising);
function dimising(e: MouseEvent): void {
mLoader.unloadAndStop();
removeChild(mLoader);
}

error in my actionscript for a sound slider I'm working on

Hello I' trying to make a sound slider in flash, while working on the code for it; I keep on getting this error Scene 1, 'S Action', Frame 352, line 8 1152: A conflict exists with inherited definition flash.display:MoveClip.isPlaying in namespace public. I'm wondering what I done to cause this error and how can I fix it?
Please get back to me if you can.
stop();
import flash.media.SoundTransform;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.media.SoundChannel;
var isPlaying:Boolean = true;
var lastPosition:Number = 0;
var mySound:takeachance = new takeachance ;
var myChannel:SoundChannel = new SoundChannel();
var myTransform:SoundTransform = new SoundTransform();
myTransform.volume = .5;
slider02_mc.groove02_mc.scaleX = .5;
myChannel = mySound.play(85,5,myTransform);
myChannel.addEventListener(Event.SOUND_COMPLETE,
soundCompleteHandler);
function soundCompleteHandler(e:Event):void
{
lastPosition=0;
myChannel.stop();
msg_mc.text = "Music stoped playing"
isPlaying = false;
}
play_btn.addEventListener(MouseEvent.CLICK,startSound);
pause_btn.addEventListener(MouseEvent.CLICK,stopSound);
function startSound(myEvent:MouseEvent):void
{
if(!isPlaying)
{
myChannel = mySound.play(lastPosition,5,myTransform);
isPlaying = true;
msg_mc.text="";
myChannel.addEventListener(Event.SOUND_COMPLETE,
soundCompleteHandler);
}
}
function stopSound(myEvent:MouseEvent):void
{
lastPostion = myChannel.position;
myChannel.stop();
isPlaying = false;
}
slider02_mc.mc.addEventListener(MouseEvent.MOUSE_DOWN, myfunction);
function myfunction(event:MouseEvent):void
{
slider02_mc.mc.startDrag(false,new Rectangle(0,0,200,0))
addEventListener(Event.ENTER_FRAME,xpos);
function xpos(event:Event)
{
var myvolume=(slider02_mc.mc.x)/200;
slider02_mc.groove02_mc.scaleX = myvolume;
volume_mc.text = "Volume is"+int(myvolume*100)+"%";
myTransform.volume = myvolume;
myChannel.soundTransform = myTransform;
}
}
stage.addEventListener(MouseEvent.MOUSE_UP,myfunction1);
function myfunction1(event:MouseEvent):void
{
slider02_mc.mc.stopDrag();
addEventListener(Event.ENTER_FRAME,msg);
function msg(event:Event)
{
volume_mc.text="";
}
}
Movieclips already have a property called isPlaying. You should change your variable to something else like soundIsPlaying.

How to remove stream video in next scene AS3

I am making a project with a video in a scene, but when I go to the next scene the video keeps appearing. How can I remove it.
My code so far is:
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.events.MouseEvent;
var videoConnection:NetConnection = new NetConnection();
videoConnection.connect(null);
var videoStream:NetStream = new NetStream(videoConnection);
videoStream.play("short_jump.flv");
var metaListener:Object = new Object();
metaListener.onMetaData = onMetaData;
videoStream.client = metaListener;
var video:Video = new Video();
video.attachNetStream(videoStream);
stage.addChild(video);
video.x=200;
function onMetaData(data:Object):void
{
play_btn.addEventListener(MouseEvent.CLICK, playMovie);
stop_btn.addEventListener(MouseEvent.CLICK, stopMovie);
}
function playMovie(event:MouseEvent):void
{
videoStream.play("short_jump.flv");
}
function stopMovie(event:MouseEvent):void
{
videoStream.pause();
}
Thanks for your support!
video.attachCamera( null ) stops audio and video but the last frame remains in the video. you should just video.visible = false afterwards so you don't see that frame. there's a bug where clear() doesn't do what it should.

How to add a Timer in AS3

I was wondering how to add an ingame Timer in AS3, I made a health bar for enemy mobs and once mob is attacked, health bar is visible. I need to add piece of code which if Enemy was not attacked for 5 Seconds, healthBar.visible = false; but I have no idea how to deal with time in AS3
any ideas ?
My suggestions are as follows:
Assumed MouseClick is Ninja attacked hero. If you using a this code you need to create Class or fit type. I just written skeleton code.
Download Source
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
stage.addEventListener(MouseEvent.CLICK, onAttacked);
var isAttacked:Boolean;
var timer:Timer = new Timer(100,50);
var alphaCount:Number = 1.0;
timer.addEventListener(TimerEvent.TIMER, onTick);
function onAttacked(e:MouseEvent):void
{
isAttacked = true;
timer.start();
}
function onTick(e:TimerEvent):void
{
alphaCount = 1.0 - ( 2 * timer.currentCount ) / 100;
if(!isAttacked)
{
goFadeStatusBar();
}
else
{
restoreStatusBar();
alphaCount = 1.0;
timer.reset();
timer.start();
isAttacked = false;
}
}
function goFade():void
{
bar.alpha = alphaCount;
}
function restore():void
{
bar.alpha = 1;
}

mp3 Looping Problems-Actionscript 3

This is so weird, this post wont let me start the sentence with hello hi or howdy maybe cache issue, anyways, hello, i'm very very new to AS3 so my knowledge is limited, hoping you pros can take it easy on the new guy :).
I'm building a flash site with an animation that loops and i've added an mp3 song as background music, it's also set to loop and auto play. the problem is, that the song is longer than the animation, and when the animation goes back to frame 1, the song overlaps the one that's still playing. I'd like for the song to fully finish before it starts playing again. yeaaah there's probably a heap of code missing, but i got closer to what i want, just need your help to polish it a little.
here is the code so far
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
//var codes
var AutoPlay:Boolean=true;
var isPlaying:Boolean=false;
var pausePosition:Number=0;
var myMusic:Sound=new Sound();
var soundFile:URLRequest=new URLRequest("Fluke.mp3");
myMusic.load(soundFile);
var channel:SoundChannel;
//if commands
if (AutoPlay==true) {
channel=myMusic.play(pausePosition);
isPlaying=true;
}
//pausebutton functions
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
function pauseSound(e:MouseEvent):void
{
if (isPlaying == false) {
channel = myMusic.play(pausePosition);
isPlaying =true;
}else{
pausePosition=channel.position;
channel.stop();
isPlaying=false;
}
}
//playbutton functions
play_btn.addEventListener(MouseEvent.CLICK,playMus ic);
function playMusic(event:MouseEvent):void
{ if (isPlaying== false) {
channel=myMusic.play(pausePosition);
isPlaying=true;
}
}
THIS is the full working code thanks to Josha, with an .addEventListener that i added so that the song would loop after its finished playing.
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
//var codes
var AutoPlay:Boolean=true;
var isPlaying:Boolean;
var pausePosition:Number;
var myMusic:Sound;
var soundFile:URLRequest;
var channel:SoundChannel;
// only create music and register event listeners one time
if (myMusic == null)
{
soundFile = new URLRequest("Fluke.mp3");
myMusic = new Sound();
myMusic.load(soundFile);
pausePosition = 0;
if (AutoPlay)
{
channel = myMusic.play(pausePosition);
isPlaying = true;
}
else
{
isPlaying = false;
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
play_btn.addEventListener(MouseEvent.CLICK, playMusic);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event) {
pausePosition = 0;
channel = myMusic.play(pausePosition);
isPlaying = true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
//playbutton functions
function pauseSound(e:MouseEvent):void
{
if (isPlaying == false) {
channel = myMusic.play(pausePosition);
isPlaying =true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}else{
pausePosition=channel.position;
channel.stop();
isPlaying=false;
}
}
//playbutton functions
function playMusic(event:MouseEvent):void
{
if (isPlaying== false) {
channel=myMusic.play(pausePosition);
isPlaying=true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
}
I can not place comments yet, so have to use answer.
Are you placing your code in separate AS files; or is this code placed at the first frame of your animation?
If the latter is the case, that indeed you will get overlapping sounds. Since the actionscript code is executed every time the playhead returns to frame 1; creating a new Sound object and starting to play that sound.
A simple solution is to create a key frame at the last frame and add the following action script:
gotoAndPlay(2);
This will loop your animation from frame 2, skipping over the action script.
Another solution that might work (you would have to test it):
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
//var codes
var AutoPlay:Boolean=true;
var isPlaying:Boolean;
var pausePosition:Number;
var myMusic:Sound;
var soundFile:URLRequest;
var channel:SoundChannel;
// only create music and register event listeners one time
if (myMusic == null)
{
soundFile = new URLRequest("Fluke.mp3");
myMusic = new Sound();
myMusic.load(soundFile);
pausePosition = 0;
if (AutoPlay)
{
channel = myMusic.play(pausePosition);
isPlaying = true;
}
else
{
isPlaying = false;
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
play_btn.addEventListener(MouseEvent.CLICK, playMusic);
}
//playbutton functions
function pauseSound(e:MouseEvent):void
{
if (isPlaying == false) {
channel = myMusic.play(pausePosition);
isPlaying =true;
}else{
pausePosition=channel.position;
channel.stop();
isPlaying=false;
}
}
//playbutton functions
function playMusic(event:MouseEvent):void
{
if (isPlaying== false) {
channel=myMusic.play(pausePosition);
isPlaying=true;
}
}