Loading external swfs and controlling their actionscript
I'm in need of some tutorials/examples for loading external
swfs placed in empty movie clips using loadmovie into the main
movie.
I have actionscript and alot of interactive features within
these loaded swf files and I'm having a heck of a time figuring out
how to code and path the AS from them to work in the main timeline.
I'm also open to using loadMovieNum and working with levels
if it might be easier, however I'd like to keep this as simple as
possible.
PLEASE ANY HELP!!!????
I am by no means an expert however it is my understanding
that if you have a loaded swf within your main application and you
wish to control features on the main timeline you need to use the
_root function.
Without knowing exactly what type of controlling you need
it's hard to explain in great detail.
Similar Messages
-
Loading External SWF and setting variables
Hello Everyone.
I'm sure you are all a where of the FlashVars attribute for
Flash embeds which holds variables for SWF's when they are
rendered. I'm attempting to load an External SWF dynamically
from within my own SWF and need to provide it with the values
normally stored in the FlashVars. For the example below I
wait until the External SWF is completely loaded using the
onLoadInit event from moviecliploader and then i attempt to
set the required variables that the loaded SWF needs. This works
great in test and debug mode (ie. Test Movie and Debug Movie
from the Control menu), but when i publish my FLA to SWF and run
the SWF the variables will NOT get set in the loaded External SWF.
From my readings ive people have mentioned that the player is only
able to access Methods of an External SWF. If this is the case then
how do they expect people to set the FlashVars of dynamically
loaded SWFs? I investigated the loadVariables procedure as well and
had the same results in test mode and was wasn't reliable because
of timing issues.
The sample source is below... if anyone has any ideas or has
come across this issue before, I would really appreciate some
insight.
Thank you in advance for your time.
var loader_mc:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
loader_mc.addListener(mclListener);
mclListener.onLoadProgress = function(target_mc:MovieClip,
numBytesLoaded:Number, numBytesTotal:Number) {
// DO NOTHING
mclListener.onLoadComplete = function(target_mc:MovieClip) {
// DO NOTHING
mclListener.onLoadInit = function(target_mc:MovieClip) {
// WORKS IN TEST MODE NOT IN PUBLISH/SWF MODE
target_mc._root.param1 = "value1";
// WORKS IN TEST MODE NOT IN PUBLISH/SWF MODE
_level0.container_mc.param1 = "value1";
this.createEmptyMovieClip("container_mc",
this.getNextHighestDepth());
container_mc._lockroot = true;
loader_mc.loadClip("somecoolflash.swf", container_mc);I've tried that as well and it behaves the same as onLoadInit
... Works when i test but doesnt when i publish to a swf. I think
this is security related and the flash player just cant write to a
loaded swf and set variables. -
Hi,
I want to know if you can load an SWF into another SWF and
control it for example:
load SWF b into SWF a and control SWF b from SWF a
is this possible because I want to be able to trigger a
particular mc or frame in SWF b but do it from SWF a?
Cheers
Scott
Text
Textyes and yes: wait until loading is complete and then
reference the target movieclip or _level of your loadMovie(),
loadMovieNum() or loadClip() method. -
Load internal SWF and control other SWF
I have 96 questions with radio button responses that control
movie clips. They are all in the same swf but I want to separate
the questions and put them in a draggable, scalable movie clip so
that the user could move the question box as convenient. Most of
the ActionScript is associated with the MCs, responding to a radio
button listener object. The two SWFs must advance from frame to
frame synchronously.
Here is what I did:
1. Split the original FLA into 2 pieces, a MC FLA and a
Question FLA
2. Renamed rbListener as _global variable in MC FLA
3. Used this code in the MC FLA:
this.createEmptyMovieClip("loadQuestions_mc",
this.getNextHighestDepth());
loadQuestions_mc._height = 400;
loadQuestions_mc._width = 600;
loadQuestions_mc.onPress = function():Void {
this.startDrag();
loadQuestions_mc.onRelease = function():Void {
this.stopDrag();
loadQuestions_mc.createEmptyMovieClip("containQuestions_mc",
this.getNextHighestDepth());
loadMovie("mccolor4_SplitBottom.swf", containQuestions_mc);
4. Used this code in the first frame of Questions FLA:
function specifyListeningTargets () {
i = cellNumber;
eval("QA" + i).addEventListener("click", rbListener);
eval("QB" + i).addEventListener("click", rbListener);
eval("QC" + i).addEventListener("click", rbListener);
// Button pops up at x:400, y:600, What is 10? Depth?;
clicking button advances to next frame.
function popupNav () {
i = cellNumber
if (((eval("QA" + i).selection.data) > 0),
((eval("QB" + i).selection.data) > 0),
((eval("QC" + i).selection.data) > 0)) {
this.createClassObject(mx.controls.Button, "popupNext_btn",
10, {label:"Go To Next Questions"});
popupNext_btn._width = 20;
popupNext_btn.move(250, 375);
function popupClicked() {
this.nextFrame();
_parent.nextFrame();
popupNext_btn.addEventListener("click", popupClicked);
5. Used this code in each frame of the Questions Fla:
stop();
cellNumber = 1;
popupNext_btn._visible = false;
popupNav ();
specifyListeningTargets();
Textyes and yes: wait until loading is complete and then
reference the target movieclip or _level of your loadMovie(),
loadMovieNum() or loadClip() method. -
Loading external swf and object error
Hello Forum,
I have two swf files, Flash CS3, action script 3.
One file can be considered to be the parent container, it
does have some objects on its stage.
The other file is a file that I would like to load into the
master file using the Loader object.
The file that I would like to load, works fine (or so it
seems) standalone. This file contains
a timer object, a loader object (which loads images from an
xml file), and XMLLoader feature,
and a button that I have created from a class that i have
created for a button. I can set the
label for the button from the swf like a property. This swf
is all Actionscript, using
addchild to get the various things on the stage.
I am using actionscript to load the objects on the stage in
the external file - as opposed to having
them on the timeline before hand.
When I try to load this external swf file in to a parent swf
file I get an error like this:
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
at weekly_tasks_fla::MainTimeline/frame1()
This error happens whenever (in the external swf file) i add
an object
(like a button or a textfield) to the stage of the exteranl
swf file.
I am able to load other swf files ok (as long as I did not
create them!).
Confused Again,
eholz1I sat typing into the quick reply, but this isn't sorry.
The issue here is that when you roll over another object
within the application it assumes that you have moved out of the
current object even if the new object is within the container of
the current object.
Hope that makes sense upto now. I had the same problem and
had to do this...
On mouse Over pr Rollover on internal object I run the stop
propogation and then restart the mouse over of the parent
container.
private function stopGadget(e:MouseEvent):void
// Stops the current mouse over running the parent container
mouse over. Then reloads the parent container for the gadget bar
(BIT OF A HACK)
e.stopPropagation();
Application.application.showTheGadget(e);
I think my comment sums it up a BIT of a Hack. -
How to load external swf and handle events of external swf by passing data .
Hi all
I have to laoad external swf (made in flash).On loading i have to pass data and hndle events which occurs on this swf.
Can any one suggest me how can I achieve this.
Regards
MuniraHere is one way:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f9c.html
HTH, -
Load external swf and consume your lybrary
dear friends flashers,
I need to load a swf into another swf and access objects that are in the library.
load a swf into another is not my problem the problem is to create an instance of an audio exported to action script contained in the child swf.
Has anyone had this problem? help me?
Thanks.
Marcio.I founded by myself, I just created a movie clip of this button and here is my code in case someone has the same problem...
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
var loader:Loader = new Loader();
loader.load(new URLRequest("MyInDesignSwf.swf"));
addChild(loader);
addChild(home_front);
home_front.addEventListener(MouseEvent.CLICK,playClickedExit)
stop();
function playClickedExit(event:MouseEvent):void
removeChild(loader);
gotoAndPlay(90); -
Loading external swf and Roll_OVER ROLL_OUT Events...
Hi.
Suppose the following scenario:
My application has some handlers attached for the rollover
and rollout events. the seem to work pretty fine. But i have to add
into my application an swf, so i add it using an Image Object. This
new Image Object containing my external swf file is into my
application. Now Roll_OUT event of my application fires when i
enter the swf Image Object, that is inside my application!!!
What am i doing wrong? I attach an example
Maybe that swf has events on it...
I am really confused about this behaviour in flexI sat typing into the quick reply, but this isn't sorry.
The issue here is that when you roll over another object
within the application it assumes that you have moved out of the
current object even if the new object is within the container of
the current object.
Hope that makes sense upto now. I had the same problem and
had to do this...
On mouse Over pr Rollover on internal object I run the stop
propogation and then restart the mouse over of the parent
container.
private function stopGadget(e:MouseEvent):void
// Stops the current mouse over running the parent container
mouse over. Then reloads the parent container for the gadget bar
(BIT OF A HACK)
e.stopPropagation();
Application.application.showTheGadget(e);
I think my comment sums it up a BIT of a Hack. -
Loading external .swf files issue...
Hi,
I'm working on a simple example of loading external swf files with some ActionScript.
I've placed an instance of List Component and gave it an instance name of loadList. Using Component Inspector, I assigned data for 4 external files as below:
Next, I've added a UILoader component (instance name - loadWindow). The code that is supposed to load the content into UILoader is this:
loadList.addEventListener(Event.CHANGE, selectItem);
function selectItem(e:Event):void
loadWindow.source = e.target.selectedItem.data;
When I run it in a FlashPlayer, it only loads the first 2 swf files.... (I checked the files and all files are fine).
I hope to get some light on the issue so any help will be appreciated.Try tracing e.target.selectedItem.data to make sure it's what you expect.
Also, have you tried using the load() method instead of the source property? -
Loading External SWF - Problem
Hi,
Using MovieClipLoader I want to load external SWFs - and it
is working fine
if external swf doesn't have anything outside it's stage,
otherwise it shows
everything - that's the problem.
For example, external swf's stage dimensions are 100x150, but
it has some
timeline animation (some objects scrolling through the stage,
some bouncing
text animation that sometimes goes off-stage, etc..).
So when I load this external movie (banner.swf), I can see
all these objects
that were bouncing outside this 100x150 area (the stage of
banner). Even
more - the size of loaded movie is larger than 100x150px
(because of these
off-stage objects that are now visible). This way I'm getting
positioning
problems, too.
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.loadClip("banner.swf", holder);
mcl.addListener(listener);
holder._x = Stage.width/2 - holder._width/2;
holder._y = Stage.height/2 - holder._height/2;
Thanks in advance,
B.Hi kglad,
Does doing that takes only into account width and height of the stage, or also considers off stage items (as in the initial question)?
I am also looking at this issue and we can't have all the content providers modify their pre-existing flash applications to be displayed in the appropiate scale. We are looking to any of the following:
find a way to get adobe air/flash to not consider the off stage elements on the width/height we set to the movie.
find a way to get the stage size from the external movie and use that to auto calculate the resize needed.
any other alternative that allows to have the same end result, which is loading up the external content at the size we specify and displaying well. We can actually hide content outside the stage, but we still need to know the appropiate scale / size to apply to the movie so what's visible matches the are where we want to show the content. -
Will app store approve an app to load external swf containing actionscript code in it?
Will app store approve an app to load external swf containing actionscript code in it?
Hi...It is not in the application bundle...it will be hosted on a server and from there it will be loaded in the application. I had created one sample application where it is loading a swf which is hosted on different server. This swf contained some actionscript code on its timeline. This app was working on ipad. I just wanted to know whether App Store will approve this.
-
I want to load external swf in movieclip and next external swf should load Automatically
I want to load external swf in movieclip and next external swf should load Automatically when current swf is finished in AS3.
How can we can check total frame and current frame of imported swf in a movie clip.
any help will be appreciated
regards,
Jatin Demblain as3 you use the loader class (not movieclips) to load external swfs.
you can use an Event.COMPLETE event listener (applied to the loader's contentLoaderInfo property) to check when loading is complete and start the next swf loading.
you can use the loader's content property (caste as a movieclip) to determine info (including totalFrames) about the loaded swf's main timelnie (once loading is initialized, for the totalFrames, or complete, for some other properties like height and width).
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadcompleteF);
loader.load(new URLRequest("swf1.swf"));
var loadedSWF:MovieClip;
function loadcompleteF(e:Event):void{
loadedSWF=MovieClip(loader.content);
trace(loadedSWF.totalFrames); -
Loading external swf not complete
Hi, I'm trying to load external swf (with more than one frame and actionscript 3 on every frame - I used there "timeline" coding) from my main swf.
code for loading external swf into main swf:
var loader01:Loader;
function openGame1(evt:Event):void
loader01 = new Loader();
var requestSWF01:URLRequest = new URLRequest("game01.swf");
loader01.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, processHandler);
loader01.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
loader01.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader01.load(requestSWF01);
addChild(loader01);
function processHandler(evt:ProgressEvent):void
var loaded:Number=evt.target.bytesLoaded;
var total:Number=evt.target.bytesTotal;
var stav:Number=loaded/total;
loaded_txt.text=(Math.round(stav*100))+" %";
function initHandler(evt:Event):void{
loaded_txt.text="";
function errorHandler(evt:IOErrorEvent):void
trace ("Error: " + evt.text);
I found out that this works only for loading swf, which has only one frame (and all actionscript on that frame)... It seems that if there are more frames, than it will not load complete swf (hmm maybe it is caused, because not all objects on frames are export in first frame). Preloading starts but after for example 20 % the event.INIT is fired and the external swf starts to play (and crashes..).
You can see this here http://bvyborcik.xf.cz/ If you click on the blue building on the left with blinking text "Start hry" you will see what happens - preloading is not completed and after clicking on first floor btn, the swf crashes...
Please is there a solution for this kind of problem? Any help or pointing is welcome.
regards Borisjust curious, is the file you want to load the swf into set up exactly the same way with the same stage size, fps, and layers?
-
Bring loaded external swf to the front
Hi,
I am now implementing to create a website using side scrolling platform game approach. Since the player/actor (character that moves according to keyborad events) should always be at the top layer, I am having difficulties to get my loaded swf on top of the player. I am currently using Flash cs6 (as3).
Basically, in my main stage, there are 3 layers. 1 for actionscript, the scond one for player and lastly for background.
Layer player contains player mc and background mc.
Background mc contains visual and collisions layers.
Anything that got to do with visual, i have to put it in visual layer.
In visual layer i have backgroundcontainer mc
So, as i put the button in the backgroundcontainer mc to call the external swf, the loaded external swf appears in the container.
(I am using load/unload snippet code to call the external swf)
I want the external swf to appear on top of the player.
for (var fl_ChildIndex_2:int = 0;
fl_ChildIndex_2 < this.numChildren;
fl_ChildIndex_2++)
this.getChildAt(fl_ChildIndex_2).addEventListener(MouseEvent.CLICK, fl_ClickToBringToFront_2);
function fl_ClickToBringToFront_2(event:MouseEvent):void
this.addChild(event.currentTarget as DisplayObject);
Any help would greatly appreciatedIf you want an object to move atop all others you can just use addChild(thatobject), where thatobject is the item you want to move atop anything else. I don't know what object(s) your loop is attempting to act on, but it appears to be trying to change the index of all child objects rather than just one.
-
Loaded external swfs with transitions
I need help getting my loaded swf files to play the "out" transition before the next movie loads. I have a main swf with 5 buttons (movie clips) that load external swf onto the stage.
package
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.events.*;
public class V2 extends MovieClip
private var sections_array:Array;
private var section_buttons_array:Array;
private var loader:Loader;
private var sectionHolder : MovieClip;
private var swf:String;
private var currentSection:int=0;
private var nextSection:int;
private var id:int=0;
private var homeLoc = "./swfs/home.swf";
public function V2()
init();
private function init():void
stop();
stage.frameRate=31;
preloader_mc.visible=false;
preloader_mc.fill_mc.width=0;
sectionHolder = new MovieClip();
sectionHolder.x = 37;
sectionHolder.y = 42;
addChild( sectionHolder );
sections_array = new Array('./swfs/section1.swf',
'./swfs/section2.swf',
'./swfs/section3.swf',
'./swfs/section4.swf',
'./swfs/section5.swf');
section_buttons_array = new Array(btn1,btn2,btn3,btn4,btn5);
addMenuListener();
addMenuEvents();
loadHome();
private function addMenuListener():void
for(var i:int=0;i < section_buttons_array.length;i++)
section_buttons_array[i].id=i;
section_buttons_array[i].addEventListener(MouseEvent.MOUSE_DOWN,loadSectionHand ler);
private function loadHome():void
swf=homeLoc;//sections_array[0];
var request:URLRequest=new URLRequest(swf);
loader=new Loader();
initListeners(loader.contentLoaderInfo);
loader.load(request);
id=0;
private function changeSection(m:MouseEvent):void
id=m.currentTarget.id+1;
loader.unload();
sectionHolder.removeChild(loader);
removeListeners(loader.contentLoaderInfo);
loadSection(m.target.parent.id+1);
private function loadSectionHandler(evt:MouseEvent)
id = evt.currentTarget.id;
loadSection(id);
private function loadSection(n:int):void
swf=sections_array[id];
var request:URLRequest=new URLRequest(swf);
initListeners(loader.contentLoaderInfo);
loader.load(request);
private function initListeners(dispatcher:IEventDispatcher):void
dispatcher.addEventListener(Event.OPEN,start);
dispatcher.addEventListener(ProgressEvent.PROGRESS,atLoading);
dispatcher.addEventListener(Event.COMPLETE,completed);
private function removeListeners(dispatcher:IEventDispatcher):void
dispatcher.removeEventListener(Event.OPEN,start);
dispatcher.removeEventListener(ProgressEvent.PROGRESS,atLoading);
dispatcher.removeEventListener(Event.COMPLETE,completed);
private function start(event:Event):void
preloader_mc.visible=true;
private function atLoading(event:ProgressEvent):void
var n:uint=(event.bytesLoaded/event.bytesTotal)*100;
preloader_mc.fill_mc.width=n;
private function completed(event:Event):void
sectionHolder.addChild(loader);
preloader_mc.visible=false;
private function stopAll():void
for(var i:int=0;i < section_buttons_array.length;i++)
section_buttons_array[i].stop();
sections_array[i].stop();
private function addMenuEvents():void
for(var i:int=0;i < section_buttons_array.length;i++)
section_buttons_array[i].mouseChildren=false;
section_buttons_array[i].buttonMode=true;
section_buttons_array[i].id=i;
section_buttons_array[i].isPressed=false;
section_buttons_array[i].addEventListener(MouseEvent.MOUSE_OVER,setOver);
section_buttons_array[i].addEventListener(MouseEvent.MOUSE_OUT,setOut);
section_buttons_array[i].addEventListener(MouseEvent.MOUSE_DOWN,setDown);
section_buttons_array[i].addEventListener(MouseEvent.MOUSE_UP,setUp);
private function setOver(evt:MouseEvent):void
if(evt.target.isPressed==false)
evt.target.gotoAndStop(2);
private function setOut(evt:MouseEvent):void
if(evt.target.isPressed==false)
evt.target.gotoAndStop(1);
private function setDown(evt:MouseEvent):void
nextSection=evt.target.id;
checkState(evt.target.id);
evt.target.gotoAndStop(3);
loadSection(1);
currentSection=evt.target.id;
private function setUp(evt:MouseEvent):void
if(evt.target.isPressed==false)
evt.target.gotoAndStop(1);
private function checkState(n:int):void
for(var i:int=0;i < section_buttons_array.length;i++)
if(i==n)
section_buttons_array[i].isPressed=true;
else
section_buttons_array[i].isPressed=false;
section_buttons_array[i].gotoAndStop(1);
private function removeSWF(e:Event):void
loader.unload();
removeEventListener("removeMe", removeSWF);
var request:URLRequest = new URLRequest(swf);
loader.load(request);
private function onClick(e:MouseEvent):void
targetID = e.currentTarget.id;
addEventListener("removeMe", removeSWF);
MovieClip(loader.content).play();
private function removeSWF(e:Event):void
loader.unload();
removeEventListener("removeMe", removeSWF);
The loaded swf has a stop() an intro animation and on the last frame have.
dispatchEvent(new Event("removeMe", true));your isse begins here ..
loadSection()
you use the same loader to not only load files but you are tyring to use it to target the movieClip you also want to play.
The issue is loader. The loader can only reference one load at a time.. otherwise you screw up your listeners and the ability to unload files properly.
You should load all files in Your current system as its own variable so that while one loads you can still control a movie.
So what type of end transitions do your files have?
What exactly with this seems like youre getting an issue.. looking at it looks alright aside from the fact that some methods are not used at all by your class
Maybe you are looking for
-
How to switch off log4j trace ...
Hi, I have different behavior of log4j on windows and Solaris. Assume I cofigured to have log on a file. On window it is fine. On Solaris it is fine too. but in later case, there are some traces printed in the screen as: *** configurationOptionStr=nu
-
ICloud duplicates in calendars and contacts
When I first synced iCloud with my pc and ipad2, all of my calendar entries were duplicated. I just got an iphone4s. I've already synced it with my outlook if I use iCloud is it going to duplicate everything again? And if so, is there a way of pre
-
Quotation Block screen in VA01
Hi Gurus how to remove the screen in sales order creation with reference of Quotation i want to block the screen quotation in VA01 Transaction can u please suggest how to do Sachin V
-
I usse comcast.net as my isn obviously and in setting up a new computer, it constantly get the message "you have selected to run rpc.html" as a popup. It is driving me crazy so if you can't help me defeat this, I will have to go back to IE and never
-
Equium P200-1ED PSPB5E - Storage and Sound drivers download
I am after the following XP drivers, but the links on the downloads are dead. "Storage Manager" - http://support2.toshiba-tro.de/ftedd-files2/0/fstormng-20070827133046.zip Realtek Sound" - http://support2.toshiba-tro.de/tedd-files2/0/sound-2007082116