button to open a swf in AS 3.0 - actionscript-3

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
}

Related

Unable to Load an external Swf

I am trying to learn Action Script (self study) and therefore I took a project for myself.So this question might be way too simple or idiotic. If it is i apologise.
The goal is simple. I have 2 swf to embed within my swf. when my swf will run, it will load 1st swf by default. when you click a button, it will load the second swf.you can return back to the first swf using a different button.
After researching I came up with the action script mentioned below. The buttons work and the 1st swf work. But the second swf does not load for some reason. No compilation error found (but got an output error "TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event#2e1785d9 to OpenEvent." but i think that is comming for the working swf because of the xml it is trying to load) . wondering why the second swf is not loading even though I used a similar code as the first and how to rectify it.
url to my swf : http://itnotes.in/RLC/swf/Radio/muses-1.2/radio-tv.swf
my fla file (flash cs6 as3) : itnotes.in/RLC/swf/Radio/muses-1.2/radio-tv.fla
Any help deeply appreciated
Security.allowDomain("avastarentertainment.com")
Security.allowDomain("itnotes.in")
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
var Xpos:Number = 110;
var Ypos:Number = 180;
var swf:MovieClip;
var loader:Loader=new Loader();
loader.load(new URLRequest('http://itnotes.in/RLC/swf/Radio/muses-1.2/muses.swf?url=http://listen.181fm.com:8002&lang=auto&codec=mp3&tracking=true&volume=65&autoplay=true&buffering=5&skin=http://itnotes.in/RLC/swf/Radio/muses-1.2/simple-gray/ffmp3-simple-gray.xml&title=Vishara%20Designs'));
loader.x=Xpos;
loader.y=Ypos;
addChild(loader);
/////////////////////////////////////////////////////////////////////////////
//Radio Function
radio.addEventListener(MouseEvent.CLICK, RadioBtnClick);
function RadioBtnClick(event:MouseEvent):void{
removeChild(loader);
SoundMixer.stopAll(); //stop all sounds...
loader.load(new URLRequest('http://itnotes.in/RLC/swf/Radio/muses-1.2/muses.swf?url=http://listen.181fm.com:8002&lang=auto&codec=mp3&tracking=true&volume=65&autoplay=true&buffering=5&skin=http://itnotes.in/RLC/swf/Radio/muses-1.2/simple-gray/ffmp3-simple-gray.xml&title=Vishara%20Designs'));
loader.x=Xpos;
loader.y=Ypos;
addChild(loader);
}
/////////////////////////////////////////////////////////////////////////////
//TV Function
tv.addEventListener(MouseEvent.CLICK, TvBtnClick);
function TvBtnClick(event:MouseEvent):void{
removeChild(loader);
SoundMixer.stopAll(); //stop all sounds...
loader.load(new URLRequest("http://avastarentertainment.com/avanced2avan/AVAncedPlayer_TX_DeSiRe_TGZ_MS_vww861102_181powerTop40_4_29_16rev11EpCc_SSER.swf"));
loader.x=Xpos;
loader.y=Ypos;
addChild(loader);
}
Your codes don't have any problems, test your project's output on your browser {in maximized window mode}.
Note:
The file
AVAncedPlayer_TX_DeSiRe_TGZ_MS_vww861102_181powerTop40_4_29_16rev11EpCc_SSER.swf
doesn't work in another domain. so it must load within http://avastarentertainment.com/
domain (another contents required for loading this file, which are accessible only on that domain {copyright} )

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 ahow to control the pause button of the external swf

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

as3 externally loaded swf from network to control externally loaded swf from network

I have had several posts like this but I have not gotten down to the final answer so I put this image together to try and explain what I am trying to do. I AM SO CLOSE.
if you can help me THANK YOU SOOOO MUCH. Worked days on this so far.
HOW DO I CONTROL CHILDREN INSIDE AN EXTERNALLY LOADED SWF FROM CODE IN ANOTHER EXTERNALLY LOADED SWF?
EDIT: Below is THEE code located in "ONE.swf" that I need help with. Just one or two lines I know but I JUST CANT get it.
function FunctionInOne()
{
var parentObj:Object = this.parent.parent as Object; //// GIVES ACCESS TO "Content.swf"
var TheStage:Object = this.parent.parent.parent as Object; //// GIVES ACCESS TO STAGE
trace(TheStage.stage.stageWidth);
trace(parentObj); /// [object MainTimeline]
trace(parentObj.ONE); /// [object Loader]
trace(parentObj.TWO); /// [object Loader]
parentObj.alpha = .3; /// NOW I CONTROL THE ALPHA OF "Content.swf" from ONE.swf
var ControlTWO:Loader = parentObj.TWO; // GIVES ACCES TO LOADER TWO
ControlTWO.alpha = .3; // NOW I CONTROL THE ALPHA OF TWO.swf from ONE.swf
BUT HOW DO I GET ACCESS TO CONTROL THE CHILDREN IN "TWO.swf" from "ONE.swf"
var TWOchildren:MovieClip = MovieClip(TWO.content); // DOES NOT WORK
TWOchildren.ChildInTWO.alpha = .3;
var TWOchildren = TWO.content as MovieClip; // DOES NOT WORK
TWOchildren.ChildInTWO.alpha = .3; // DOES NOT WORK
TWOchidren.FunctionInTWO(); /// DOES NOT WORK
}
EDIT: March 16th, 2012
I am able to access the swf TWO.swf from ONE.swf and control it's alpha with this line:
trace(MovieClip(parent.parent).ONE);
But I need to control a child in that so I thought this following code would work but it doesn't:
MovieClip(parent.parent).ONE.TheChild.alpha = .3;
END EDIT---------------
Here is another link to it if you can see it: http://mycontactcorner.com/sandbox/testing/ChildTwo.jpg
Ok I found it!
var InsideConent:Object = this.parent.parent as Object; //// GIVES ACCESS TO "Content.swf"
var ItWorksNow:Sprite = MovieClip(InsideConent.TWO.content).ChildInTWO; ///
ItWorksNow.x = 333; /// I can control property x
ItWorksNow.alpha = .3; /// I can control the ALPHA! :)
Is see hard style of programming :]
to Your loaders add this , it should help:
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
var loader:Loader = new Loader ( urlRequest , new LoaderContext(false, ApplicationDomain.currentDomain));
Second thing :
You should try access to content if You make sure that its loaded .
So put start loading of second SWF to loading complete function of first SWF and You should trace(TWO.content) and see is there anything already loaded.
MovieClip(parent.parent).function();
vise versa reference the movieclip.OtherChildmoviename.function();
this structure you can call a function from where ever or anymovie for better explanation check actionscript 2 as it uses the _root, this may make the above clearer
let us no how you go;

Action Script 3 new loader

I was revisiting some code for a simple picture viewer that I created in Action Script 2.0 now taking on the same task in AS3. At present i'm well aware that the command .loadMovie is no longer used. After numerous attempts to find a solution I have come up dry.
At the moment I have a movie clip symbol(target_mc) on the stage that I want to load jpegs from a external file when I mouseOver a button. Can any one give a example of how this should be approached using the "new load" variable.In the AS2 version i also used (on release) in the button code.
training_btn is the button instance.
Please see an example of my code below:
training_btn.addEventListener(MouseEvent.CLICK, imageOver);
function imageOver(evt:MouseEvent) {
this.target_mc.loadMovie("galleryimage/p_traininglink.jpg")
}
Any ideas would be very helpful.
Wayne
Here at the Republic of Code is an excellent step-by-step tutorial on how to work with the loader class in as3
Yeap
training_btn.addEventListener (MouseEvent.MOUSE_UP, onMouseUp);
function onMouseUp (evt:MouseEvent):void {
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("myPhoto.jpg"));
target_mc.addChild(my_loader);
}
So, basically the whole structure of the laoder has change between AS 2 and 3.
Now you need to create a different object that loads the content.
var loader:Loader = new Loader();
Than you can do two things:
Add event listener and than trigger the load
Trigger the load and add the loader to the stage
The difference between these two style is big, the first one will add a listener and wait for the load to complete and after that it will call a method you define in the listener to do any further instuctions.
The second one starts loading the content and adds the loader to the display list so that when the content is loaded it automatically displays.
1.
// add the listener
laoder.contentLoaderInfo.addEventListener( Event.Complete, onLoadComplete );
// trigger the load (remember: the url is alwais a URLRequest object)
loader.load( new URLRequest("path_to_file") );
// additional var for storing the content (only the content, without the loader)
var content:Bitmap;
function onLoadComplete( e:Event ):void{
content = e.target.content as Bitmap;
// you could use also:
// content = loader.content as Bitmap;
// you can do some modifications before displaying the content
// and finally add it to the display list
this.target_mc.addChild( content );
}
2)
// trigger the load (remember: the url is alwais a URLRequest object)
loader.load( new URLRequest("path_to_file") );
this.target_mc.addChild( loader );
The two ways are correct but I prefer using the first one cause it gives you more controll. You can also check out the progress of loading by listening to the ProgressEvent.PROGRESS.
link: Loader Documentation
link: URLRequest Documentation
Hope it helps. Search in google for more info about loading external data, there's a lot of resource about that.
It would probably best to create a Class that would handle all of this, but to answer your question, your code would look something like:
var outLoader:Loader = new Loader();
outLoader.load(new URLRequest("outImage.jpg"));
var overLoader:Loader = new Loader();
overLoader.load(new URLRequest("overImage.jpg"));
overLoader.visible = false;
var training_btn:Sprite = new Sprite();
training_btn.addChild(outLoader);
training_btn.addChild(overLoader);
training_btn.buttonMode = true;
training_btn.mouseChildren = false;
training_btn.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
training_btn.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
addChild(training_btn);
function rollOverHandler(e:MouseEvent):void {
overLoader.visible = true;
}
function rollOutHandler(e:MouseEvent):void {
overLoader.visible = false;
}