AS3 ahow to control the pause button of the external swf - actionscript-3

I just trying to control buttons of external loaded swf .
var swfRequest:URLRequest = new URLRequest('http://mysite.com/player/001.swf');
var swfLoader:Loader = new Loader();
swfLoader.load(swfRequest);
var holder:MovieClip = new MovieClip();
holder.addChild(swfLoader);
addChild(holder);
And in main swf I created new button with Instance Name : pauseBtn , I want this button communicate to external swf witch has pause button with Instance Name : pausebtn in action script 2.0
external btn:
on (release)
{
status_playing = false;
playbtn._visible = true;
pausebtn._visible = false;
stop ();
}
Please help me how to communicate with these buttons.

Normally, I don't think you can directly communicate between AS3 content and AS2 content. One way around it is using a LocalConnection object to handle the communication between the two.
How it would work after creating the objects and connecting them, is the main swf would send a message to it's LocalConnection object and the loaded swf would receive that message on and use it to handle whatever you need it to.
LocalConnection - AS3 Reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html
LocalConnection - AS2 Reference: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001176.html#312868

Related

AS3: use buttons in external swf

I am making a website in Adobe Flash that imports it´s navigation buttons from an external swf-file.
The problem is how my Main FLA-file will know which of the navigation buttons the users has pressed, since the buttons and it's eventListeners are in the external swf-file.
With other word: can I make my external swf-file return a Number to my website FLA-file, to determine which button that have been pressed? If so, how?
You can set up a connection between the external swf and main swf using the LocalConnection()
In main.swf
var sending_lc:LocalConnection;
sending_lc = new LocalConnection();
function send_it(evt:MouseEvent):void
{
sending_lc.send("connectionName", "functionName", "myData");
//params are (connection name, function to execute in the receiving swf, the data to pass through)
}
my_btn.addEventListener(MouseEvent.MOUSE_UP, send_it);
In exetrnal.swf
var receiving_lc:LocalConnection;
receiving_lc = new LocalConnection();
receiving_lc.connect("connectionName");
receiving_lc.client = this;
function functionName(data:String):void {
trace(data);
}

Unable to load SWF in as3

I am working in flash and as3. I am new to as3. I was trying to load and unload the SWF file.
My project contains 2 files, one is index file and the other is animal file. In the index page I have button for animal. When I click on this button the animal SWF starts executing. But the problem is when I click on index button of animal SWF, it is not showing index page again, instead it is showing message as
Unable to load SWF
My index page code is:
var urlReq:URLRequest = new URLRequest("animal/animal.swf");
swfLoader.load(urlReq);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadComplete);
swfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
swfLoadError);
function swfLoadComplete(evt:Event):void
{
var loader:Loader = Loader(evt.target.loader);
addChild(loader.content);
swfLoader.removeEventListener(Event.COMPLETE, swfLoadComplete);
}
function swfLoadError(evt:IOErrorEvent):void
{
trace("Unable to load swf ");
swfLoader.removeEventListener(IOErrorEvent.IO_ERROR, swfLoadError);
}
So what to do to load the index SWF from animal SWF?
You probably forgot to add to the displaylist. Use addChild.
var urlReq:URLRequest = new URLRequest("animal/animal.swf");
swfLoader.load(urlReq);
this.addChild(swfLoader);
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html
Update: I see its not loaded. You have an IOErrorEvent.IO_ERROR. Mostly this means the file is not located at that url. Check the location or use a http debugger to find out which location you are trying to open.

load an external swf (FlashPaper pdf) into a flash project

I have to do a very simple swf application able to show a series of pdf files.
Actually I was able to create on a single layer the menu interface (some buttons on frame 0 which redirect the user to other frames where the pdf should be showed).
Here my question:
I need a way to read the pdf inside the flash frame.
I've found a possible solution converting the pdf into an swf with FlashPaper 2
Now I wish to know how import the swf into the frame.
Reading some actionscript 3 guides I was able to create a container movieclip (a simple rectangle) into which I have loaded the swf with this code:
var swf:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("test.swf"); //test.swf is my converted pdf
loader.load(defaultSWF);
screen_01.addChild(loader); //screen_01 is the container rectangle converted to movieclip
I've used a container movieclip to mantain the other objects (menu buttons) on the frame, and ecause it helps with the swf positioning.
I seen it is possible also using loader.x and loader.y and it works.
Unfortunately I wasn't able to control width and height of the swf/pdf file (loader.width and loader.height exists but if used cause the swf will not loaded at all)
Solution:
I've found a possible solution at this page. The idea is to change swf scale only after the load process is complete (positioning can be done even before).
Anyway I had to use Actionscript 2 for this project because FlashPaper converted pdf doesn't work properly with AS3, I don't know why...
here the code:
//insert an emplty movieclip to load the swf, I've called it screen_01
var movLoad:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myListener.onLoadInit = function(thisMc:MovieClip) {
thisMc._height = 600;
thisMc._width = 900;
thisMc._x = 50;
thisMc._y = 30;
};
movLoad.addListener(myListener);
movLoad.loadClip("folder/flashpaper_converted_pdf.swf.swf",screen_01);
You can modify the size of the loader using scaleX and scaleY properties.
Keep them equals so the swf isn't stretched.
You may also want to listen to the COMPLETE event to do such a thing :
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event)
{
var loader:Loader = e.currentTarget.loader;
loader.scaleX = loader.scaleY = 2; //Double the size of the loaded swf
}

button to open a swf in AS 3.0

I have been trying to find the appropriate code for this during hours. But none of the ones I found seem to work. I really need help with it...I am desperate...
I have 2 swf files. I added a button to the end of the 1st swf file (the next button).I want to go to the 2nd swf file when pressing this button. I know how to do it with actionscript 2.0 (LoadMovie)...but I started my swf in actionscript 3.0 and now ...I need to code that in AS 3.0.
Could anybody help me with this code?? I tried with some of the codes i have seen from other users, but i don't know what i am doing wrong that any of them work for me !!
Thank you very much!
This should help:
// Set the URL of the second movie
var url:String = "url_of_your_second_movie"
// Create the loader object using the specified URL
var loader:Loader=new Loader();
var request:URLRequest;
request= new URLRequest(url);
// Set the COMPLETE event handler
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete );
// Start the load
loader.load( request );
// Fill the COMPLETE event handler as needed
private function onComplete(e:Event):void
{
// Add the loaded content to the display list
addChild(e.currentTarget.content);
// Do whatever else is needed once the movie is completed
}

Load AS2 SWF Into AS3 SWF and pass vars in URL

I've got an AS3 SWF that I'm going to be loading other SWFs into. These child SWFs all take a single parameter on the URL. I can't seem to get it working when loading an AS2 child, and it needs to be able to handle both.
so I have
var request:URLRequest = new URLRequest();
var loader:URLLoader = new URLLoader();
request.url = "http://domain/as2.swf?param=foo";
loader.load(request);
// etc on to the eventListeners, addChild, etc
When the as2 SWF gets loaded, it can't see the parameter I've passed to it. It's looking for _root.param. Am I doing this wrong or am I attempting the impossible?
EDIT: I should add that I can load a SWF with those URL params from an AS2 loader and it works just fine.
It's not trivial to communicate between AS2 and AS3 since they run in different virtual machines. Check this http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html for some hints.
Edit: If you cannot change the loaded as2 content your only options is creating a 'wrapper' as2 loader that uses the linked example above to communicate with the as3 and interfaces with the loaded as2 content using _root.varname This is not pretty but it might just work.
It might be worth trying to assign the variables dynamically after the SWF has loaded but before you add it to the stage. Ie.
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded);
function movieLoadedHandler(event : Event) : void
{
var loaderInfo : LoaderInfo = event.target as LoaderInfo;
var clip : DisplayObject = loaderInfo.content;
for each(var prop in varsToTransfer)
{
clip[prop] = varsToTransfer[prop];
}
// add to parent
}
Let me know how that goes.
AS3 -> AS3
Movie 1(www.domain1.com):
Load the external movie when click a "buy" button...
buy.addEventListener(MouseEvent.CLICK,function(){
var ldr:Loader = new Loader();
var url:String = "http://www.domain2.com/movie.swf?a=b&c=d";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);
});
Movie 2(http://www.domain2.com/movie.swf):
var mc:MovieClip = this as MovieClip;
var ldi:LoaderInfo = mc.loaderInfo;
var lobj:Object = ldi.parameters as Object;
for (var l in lobj) {
dumper.htmlText += l+" => "+lobj[l]+"<br />";
}
"dumper" is the name of the Dynamic Textbox field located in Movie2.
The output should look like:
a => b
c => d
Instead of looking for _root.param, use _root._url then parse out your parameters by hand.
var url: String = _root._url;
var param: String = 'param=';
var paramStart: Number = url.lastIndexOf(param);
var paramValue: String = url.substring(paramStart + param.length, url.length);
trace(paramValue);
SWFBridge is awesome and overkill for something like this.
You are doing it wrong.
"http://domain/as2.swf?param=foo"
Is a request for the file named as2.swf, on the server named domain. Any ?param=foo parameters that are part of that http request are lost when the request is complete. If the server needed to do something according to these variables, it would, but you are asking a .swf file to detect these variables, that's just silly.
Put a variable in your Global object (Global namespace) for the flash player, then when the as2 .swf is loaded into that flash player it will have access to the variable you set in your Global object.
I am not proficient in as2, but in as3, the Global object can be accessed with the this keyword, at the package level (probly is the same for as2, just dont worry about setting it at a package level).