how to export movieclip as swf? - actionscript-3

I have a movieclip loaded I modify and show in swf loader in flash builder 4.5 project,
I want the user to be able to save the movieclip to his disk as swf is there a straight
forward way to do that?
I searched for suggestions and found this but nothing seems to work

completed the project finally thanks to the "AS3SWF" class
here is how I save my files after importing the library to my project
import com.codeazur.as3swf.SWF;
var swf:SWF = new SWF(mySwfMc.loaderInfo.bytes);
var ba:ByteArray = new ByteArray();
swf.publish(ba);
var C:ByteArray = new ByteArray();
C.position = 0;
C.writeBytes(ba);
var f:FileReference = new FileReference ;
f.save(C,"demo.swf");

Related

How can I unload an SWF that is already loaded to my file on actionscript3

I am trying to make a system that is first unloading any existing (loaded) flash SWF's and then loading one back in (so they won't overlap each other).
I am using a class AS3 file
My code looks like
var myLoader:Loader = new Loader();
removeChild(myLoader);
myLoader.unload();
var url:URLRequest = new URLRequest("URL HERE");
myLoader.load(url);
addChild(myLoader);
As you can see I'm trying to unload everything first, and then load the new stuff, for some reason it's not working.
Thanks in advance guys!
This line creates a new Loader object.
var myLoader:Loader = new Loader();
It's pointless to call unload() on that object, because there's no way anything could be loaded.
What you should do instead is to work with a single Loader object. Do not create new one every time.

AS3-embedded SWF comes up as null

So I have a SWF embedded in my AS3 project, but when I try to do anything with it, it says it's null.
The code looks like this:
[Embed(source = "../lib/Introduction.swf", mimeType = "application/octet-stream")]
public var introClass:Class;
(after a bunch of irrelevant stuff...)
var intro:MovieClip = new introClass() as MovieClip;
intro.play();
(The error message it gives me is a standard #1009 error.)
I've tried a bunch of stuff including using Loaders, not using MovieClip, etc, but at best, only the audio (not the video) of the SWF loads up, and at worst, the entire application crashes when the SWF tries to load. How do I get the SWF to be recognized?
(I'm using FlashDevelop if that helps.)
You can do this:
[Embed(source="asset.swf", symbol="symbol")]
private var symbolClass:Class;
var symbol:MovieClip = new symbolClass();
If you want to embed a symbol from an art SWF.
Instead if you want to import animations this is the solution:
[Embed(source="/loading.swf", mimeType="application/octet-stream")]
public var LoadingAnimation : Class;
// allows us to import SWFs to use as animations
var context : LoaderContext = new LoaderContext (false,
ApplicationDomain.currentDomain);
context.allowCodeImport = true;
var loader : Loader = new Loader ();
loader.loadBytes (new LoadingAnimation (), context);

embed sound so that when publish we do not have to include it in the same folder as the swf file

i have a flash animation with sound that have play,pause,stop,go to start and go to end button.
when i publish it i have to include the mp3 file along with the swf file.
how do i do to get the swf file alone in order to play the whole thing?
i am using flash cs 3 and actionscript 3.0
here is my codes:
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var soundIsPlaying:Boolean = true;
mySound.load(new URLRequest("saloma.mp3"));
myChannel = mySound.play();
all those buttons will go to functions,
go.addEventListener(MouseEvent.CLICK,govid);
function govid(event:MouseEvent):void{
play();
if(!soundIsPlaying){
myChannel = mySound.play(lastPosition);
soundIsPlaying = true;
}
}
i am also using scenes to navigate them,
gte.addEventListener(MouseEvent.CLICK,gotoend);
function gotoend(event:MouseEvent):void{
gotoAndStop(1,"ending");
}
thank you :)
I would have written the answer, but this has been answered already...
First, in your library, set the class linkage of a sound file by right clicking, selecting properties and editing the Class field in the Linkage section. In this example it will be Class:FogHorn
import flash.utils.getDefinitionByName;
var SoundClass:Class = getDefinitionByName("FogHorn") as Class;
var newSound:Sound = new SoundClass();
newSound.play()
source: #Allan in Actionscript 3: playing sound from library with name from string
import your mp3 file to your library
select your mp3 file in the library and right click on it
a pop-up window will appear (click on advanced if it is not yet clicked)
under the actionscript linkage, you will see class field, type "sound1" for example (no 5. quotations, this can be any other name aside from sound1)
instead of var mySound:Sound = new Sound(); this code, type
var mySound:Sound = new sound1(); //sound1 is the name of your linkage/class
You don't need this codes anymore. You need to omit your myChannel variable.
mySound.load(new URLRequest("saloma.mp3"));
myChannel = mySound.play();
To play the sound, simply type
mySound.play();

URLRequest multiple SWF links not working properly

I'm trying to load 3 different tickers in 3 different containers.
When I delete this line:
loader2.load(new URLRequest("http://tickers.playtech.com/jackpots/new_jackpot.swf?casino=cityclub&info=1&game=bl&font_face=Arial&bold=true&font_color=FFFFFF&bg_color=240000&font_size=24&currency=eur"));
loader3.load(new URLRequest("http://tickers.playtech.com/jackpots/new_jackpot.swf?casino=cityclub&info=1&game=bl&font_face=Arial&bold=true&font_color=FFFFFF&bg_color=240000&font_size=24&currency=eur"));
and load them separately they works fine:
but when i load them together, just as the written in this document in adobe, all three tickers showing the same number:
package {
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
public class importExternalSWF extends MovieClip {
private var loader:Loader = new Loader();
private var loader2:Loader = new Loader();
private var loader3:Loader = new Loader();
public function importExternalSWF() {
loader.load(new URLRequest("http://tickers.playtech.com/jackpots/new_jackpot.swf?casino=cityclub&info=1&game=mrj-4&font_face=Arial&bold=true&font_color=FFFFFF&bg_color=240000&font_size=24&currency=eur"));
loader2.load(new URLRequest("http://tickers.playtech.com/jackpots/new_jackpot.swf?casino=cityclub&info=1&game=bl&font_face=Arial&bold=true&font_color=FFFFFF&bg_color=240000&font_size=24&currency=eur"));
loader3.load(new URLRequest("http://tickers.playtech.com/jackpots/new_jackpot.swf?casino=cityclub&info=1&game=grel&font_face=Arial&bold=true&font_color=FFFFFF&bg_color=240000&font_size=24&currency=eur"));
ticker1.addChild(loader);
ticker1.width=50;
ticker1.height=20;
ticker2.addChild(loader2);
ticker2.width=50;
ticker2.height=20;
ticker3.addChild(loader3);
ticker3.width=50;
ticker3.height=20;
}
}
}
I cant find solution anywhere
Thanks
edit
I rewrite my code to this, and its still the same result
public class importExternalSWF extends MovieClip {
public function importExternalSWF() {
var url = "http://tickers.playtech.com/jackpots/new_jackpot.swf";
var urlParams:Array = ["grel", "bl", "game=mrj-4"];
var tickers:Array = [ticker1, ticker2, ticker3];
var tickerHeight:Number = 50;
var tickerWidth:Number = 50;
loadUrls();
function loadUrls():void {
for(var i:uint = 0; i<urlParams.length; i++)
{
var urlLoader = new Loader();
var flashvars:URLVariables = new URLVariables();
flashvars["casino"] = "cityclub";
flashvars["info"] = "1";
flashvars["game"] = urlParams[i];
flashvars["currency"] = "eur";
flashvars["font_face"] = "arial";
flashvars["bold"] = "true";
flashvars["font_size"] = "10";
flashvars["bg_color"] = "0x000000";
flashvars["font_color"] = "ffffff";
var request:URLRequest = new URLRequest(url);
request.data = flashvars;
urlLoader.load(request);
tickers[i].width=tickerWidth;
tickers[i].height=tickerHeight;
tickers[i].addChild(urlLoader);
}
}
}
I suspect that the external SWF file sets some variables on the root level. Therefore each load will override the previous values and you'll end up with the same score in all "tickers".
Most likely this interference can be resolved by loading each SWF into its own ApplicationDomain. By default, SWFs are being loaded into the same ApplicationDomain and share their code.
So instead of doing this:
urlLoader.load(request);
You should do soemthing like this:
// create a new LoaderContext with a spearate ApplicationDomain
var context:LoaderContext = new LoaderContext(false, new ApplicationDomain());
// load the request and use the context with the separate ApplicationDomain
urlLoader.load(request, context);
I have bad news, i tried everything, but I can't load correctly the swf files. So, I have started to investigate this, and i found that, first, your SWF has AVM1Movie format (new_jackpot.swf), so, I conclude that this SWF was created with version 1 or 2 of ActionScript. If you see the reference of AVM1Movie Class (here the link), says the following:
There are several restrictions on an AVM1 SWF file loaded by an AVM2 SWF file:
The AVM1 SWF file that is loaded by an AVM2 SWF file cannot load another SWF file into this. That is, it cannot load another SWF file over itself. However, child Sprite objects, MovieClip objects, or other AVM1 SWF files loaded by this SWF file can load into this.
Then, i tried too, with a library that implements Threads in Flex, and found this (here this link async-threading):
The Actionscript Virtual Machine (AVM) in the Flash Player is severely limited by only having one thread...
I have created several projects using Loaders, SWFLoaders, ByteArrays, etc, all this in actionscript 3 in Flex SDK 3.2.
Maybe if you create this project in a previous version could work, or try to use same library that implements threads.
Anyway if I find something more, will edit this answer with another solution that's right.
Try adding a 1 after «laoder» at these places:
private var loader:Loader = new Loader();
loader.load(new URLRequest("http://tickers.playtech.com/jackpots/new_jackpot.swf?casino=cityclub&info=1&game=mrj-4&font_face=Arial&bold=true&font_color=FFFFFF&bg_color=240000&font_size=24&currency=eur"));
There was no solution to this issue due to lack of compatibility from third part company that provides the tickers.

Access swf component from another swf file

Greeting,
I have two flash files myVideo1.swf and myVideo2.swf
Each one contents FLVPLAYBack component .
myVideo1.swf FLVPLAYBack component instance name is “video1”
myVideo2.swf FLVPLAYBack component instance name is “video2”
I want to be able to access myVideo2.swf from myVideo1.swf using as3.
I want when I click play button on myVideo2.swf the myVideo1.swf would stopped.
Bother flash files are in the same folder.
Please advice how to do this in action script 3
Regards,
First when you load your swf you need to set the loader context domain to your current domain
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
var request:URLRequest = new URLRequest('swf/assets.swf');
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader.load(request, context);
Then you can access library items set to export using:
var MyClass:Class = Class(ApplicationDomain.currentDomain.getDefinition("export_id"));
var myInstance:Sprite = new MyClass() as Sprite;