AS3 Access a Loaded SWF By Name
Hello All,
In AS3, when an swf is loaded via the Loader class, how do I
access the loaded swf by name? Here is my code:
stop();
var loader:Loader = new Loader();
var whichMovie:String = "main.swf";
addChild(loader);
function wakeLoadBar():void{
loadBar.gotoAndPlay("fadeIn");
function loadTheMovie(theMovie:String):void{
trace("LOADTHEMOVIE");
loader.contentLoaderInfo.addEventListener(Event.OPEN,
onLoaderOpen);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
onLoaderProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onLoaderComplete);
loader.load(new URLRequest(theMovie));
function onLoaderOpen(event:Event):void{
trace("OPEN");
function onLoaderProgress(event:ProgressEvent):void{
var percent:Number = Math.floor(event.bytesLoaded /
event.bytesTotal * 100) + 10;
loadBar.gotoAndStop(percent);
trace("Progress " + percent);
function onLoaderComplete(event:ProgressEvent):void{
trace("Progress Complete");
wakeLoadBar();
function loadTheMovie is called after the loader "fadesIn"
and the movie begins to load.
Let's say that after the movie loads, I want to change its x
and y, how do I go about doing that?
laodedMovieName.x = 50;
laodedMovieName.y = 150;
KGlad,
LOL... You rock!
Thanks,
V
Similar Messages
-
I'm using this code to bring in another swf into a movieClip called "movieLoader":
var myLoader:Loader = new Loader();
movieLoader.addChild(myLoader);
var urlMovie:URLRequest = new URLRequest("movie1.swf");
myLoader.load(urlMovie);
The movie loads just fine, but how do I access it?
I tried:
trace(movieLoader.totalFrames);
and it just gave me "1". I know the movieclip has more than 1 frame.
What do I do to access the swf called "movie1.swf" I just brought into that movieClip?The swf you loaded is inside the Loader. Since you have direct access to that Loader, you don't need to target its content thru the movieLoader mc. But you do have to wait until after the swf is loaded, so you will need to have a listener assigned to the Loader for completion of loading. In that listener's event handler function you can then access the loaded swf using something like...
MovieClip(myLoader.content)
OR
MovieClip(evt.target.content)
if evt is the argument opassed to the handler function -
Script access for loaded SWFs in Flash CS3
In ActionScript 2 I would do the following:
var loader:MovieClipLoader=new MovieClipLoader();
var listener:Object=new Object();
loader.addListener(listener);
listener.onLoadInit=function(m:MovieClip) {
m.something="12345";
loader.loadClip("foo.swf",placeholder);
What is the equivalent for this in ActionScript 3? I can load
a MovieClip with the Loader class, but I don't know how to get or
set one of the variables in the root timeline.So long as the movie you loaded in is also AS3, you can just
type the name of the loader object and then use dot syntax to grab
the variable. If the loaded movie is AS2, you are a great deal more
limited. I don't think you lose all control 100% over the lodaed
movie but I think it takes leaps and bounds to get at the AS2
vars. -
[AS3] Access library object by variable name
Let's say I have a button which sets the variable color to
green:
var color:String = "green"
I have a movieclip in my library called "green". With AS2 we
could simply use:
whatever.attachMovie(color, "someclip", 1);
In AS3 this works perfectly fine:
var whatever:Sprite = new green ();
to use the variable I tried the following:
var whatever:Sprite = new this[color] ();
but the movieclip is not loaded. Any ideas?flash.utils.getDefinitionByName might help you. But you'll
need to fully
qualified class path.
var color:String = "green";
var ClassReference:Class = getDefinitionByName(color) as
Class;
var instance:Object = new ClassReference(); -
Controlling loaded SWF inside a child
Hello to everyone, may this question be too obvious to
everyone, but I've been googling for hours without any luck.
Have seen examples but they are not exactly as my scenario...
Please, I need some help.
I have loaded a SWF and attached to a MovieClip which exist
in my current movie using the following code, and now I just want
to access the loaded SWF to send it orders like play() or
gotoAndPlay(); I have tried also: container=
MocieClip(loader.content); instead adding child, but it trhows an
error//this is your minimum code to load a file
var url:String = "put your url here ";
var request:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
loadComplete);
function loadComplete(event:Event):void {
addChild(loader.content);
//you don't need all that code just concentrate on the bit
you need; when this work then you can start putting the rest -
Is it possible to load content into a loaded swf?
I'd like to access a loaded SWF and load images/videos into it and trigger functions inside the loaded *.swf.
Is this possible ??Yes, see the "Chromeless..." examples in the Example Player sample app. The basic idea is that you subclass SWFElement and map the SWF's API into the MediaElement API, so that your SWFElement subclass can be handed to a MediaPlayer, integrate with compositions, etc.
-
AS3 Accessing External SWF objects
Hello
I do understand that in Flash 8 (AS2) you can create and
empty clip, then load SWF file and access objects inside it through
this movieclip. For example if I have an instance of somethig
called "inst" and I compile SWF, then after I load it in another
project I can do MovieClipName.inst._x = 50;
Now in Flash 9 (AS3) I cant do that, since I have to use the
loader, and if I try to do LoaderName.inst._x = 50 - that would not
work. So how should I have to do this now?
In few words I have a project called MainProject.fla there I
load up a movie with this:
var _ldr:Loader = new Loader;
var _req:URLRequest = new URLRequest("test.swf");
_ldr.load(_req);
Now in test.swf I have a bitmap with instance called
"MyBitmap" . How can I change position of that bitmap in that SWF
file after I load it?Thanks so much! That indeed did work.
One more question though. Can I add event listeners to the
objects inside the loaded SWF? -
Can't Access MovieClips and Functions in Loaded SWF
Hi everybody,
I'm trying to simply access anything inside this loaded SWF and all I get is 'null'.
I have code in the parent SWF that needs to tell the child SWF movieclip what to do but nothing works. This was a piee of cake in AS2 and I can't seem to get anything to crossover in AS3.
Here's my code:
import com.greensock.TweenMax;
import flash.display.MovieClip;
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("SWCS_S3_500x250_exp_panel_2.swf"); // in this case both SWFs are in the same folder
myLoader.load(url); // load the SWF file
panel2.addChild(myLoader); // add that instance to the display list, adding it to the Stage at 0,0
panel2 = myLoader.content as MovieClip;
photo_about.alpha = 0;
photo_downloads.alpha = 0;
//panel2.content_about.alpha = 0;
//panel2.content_downloads.alpha = 0;
function closeSection():void
panel2.controlsMC.forcePause();
TweenMax.to(photo_about, .5, {alpha:0});
TweenMax.to(photo_downloads, .5, {alpha:0});
TweenMax.to(photo_home, .5, {alpha:0});
TweenMax.to(panel2.content_about, .5, {alpha:0});
TweenMax.to(panel2.content_downloads, .5, {alpha:0});
TweenMax.to(panel2.controlsMC, .5, {autoAlpha:0});
TweenMax.to(panel2.content_home, .5, {alpha:0});
panel2 traces null and all the clips loaded within pull up undefined property errors.
Can somebody please tell me what I'm doing wrong? I'd be stoked to know what I'm missing and feel like this should be a piece of cake.
Thanks for any help!You are not adding the content to the stage at 0,0, you are adding it to panel2 at 0,0. THen you take panel2 and assign it to be something that likely doesn't exist by the time you assign it. You need to wait until the loader completes loading before you attempt to do anything with its content, otherwise it has no content (null). Similarly, you cannot control anything in the loaded swf until it has finished loading. So assign an event listener to the contentLoaderInfo property of the Loader to determine when loading is complete, and have the event handler function deal with starting the interaction with it.
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("SWCS_S3_500x250_exp_panel_2.swf");
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, processLoadedSWF);
myLoader.load(url);
function processLoadedSWF(evt:Event):void {
// deal with the loaded swf here
// but you don't want to be assigning it to the panel2 object that contains the loader
As far as controlling anything inside the swf you load, is it an AS1/2 or an AS3 swf? -
Acessing loaded swf movieclip sctructure on as3
Hi, I'm using external swf files to add skins to an
application. Currenlty,I'm loading isolated elements successfully
by the use of the Loader class. However, now I want to load a more
complex skin structure that will have some movieclips already
placed on the loaded swf stage. The question is: when I load an swf
that athe edit time, I placed some elements on stage and gave them
instance names, how can I access this external swf movieclip
structure? It's something like this:
1. First, I create the external file by placing some elements
on its stage, naming these elements instances, like "console_bar"
and "console_button".
2. Then, I load this swf using the Loader class (into a
loader called "playerConsole", for example) and, whe it finishes
loading I try to access the elements placed on stage:
this.addChild(playerConsole);
playerConsole.console_bar.x = 0; // won't work - how can I
access this instance?This code generates an error when I try to compile:
1119: Access of possibly undefined property console_bar
through a reference with static type
flash.display:DisplayObject. -
Access the property of main class in loaded swf.
Hi
i have one main.fla, its document class is main.as. the code in main.as is
package
import flash.display.MovieClip;
public class Main extends MovieClip
private var loading:Loading;
public var trovami:Number=10;
public function Main()
stage.frameRate=31;
loadSWF();
private function loadSWF():void
loading=new Loading(this);
Loadind.as is another class where i load another swf its name is my_swf.
the code of loading class is:
package
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.text.TextField;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;
public class Loading extends MovieClip
private var _fla:MovieClip;
private var url:String;
public var val:String;
private var loader:Loader;
public function Loading(fla:MovieClip)
_fla=fla;
init();
private function init():void
url='my_swf.swf';
var request:URLRequest=new URLRequest(url);
loader=new Loader();
initListeners(loader.contentLoaderInfo);
loader.load(request);
private function initListeners(dispatcher:IEventDispatcher):void
dispatcher.addEventListener(Event.COMPLETE,completato);
private function completato(event:Event):void
_fla.addChild(loader);
loader.y=10;
val="hello"
and the document class of loaded swf is Main2. in my_swf.fla there is one text its name is:
a_txt.
so i have to use property of Loading class in Main2 for text.
code of Main.as is
package
import flash.display.MovieClip;
import flash.text.*;
public class Main2 extends MovieClip
public function Main2()
a_txt.text=val;
where val is the property of Loading class.
so how can i access.You have a reference to your loaded movie within your Loading class - instead of just setting val to a string - add a method in your Main2 class - and call that from Loading - passing the string to it. Push not pull...
Main 2 becomes:
public function Main2() {
//a_txt.text=val;
public function setText(val:String):void {
a_txt.text = val;
And then in your Loading class - when you're done loading just call setText:
private function completato(e:Event):void
addChild(loader);
loader.y=10;
MovieClip(loader.content).setText("hello");
//val="hello"; -
How to access properties of symbols in loaded SWF?
I'm making the migration from Flash to Flex, but I'm running
into a dead end on one particular area: accessing and manipulating
properties of symbols in a loaded SWF.
The SWF is actually a simple library of a detailed parts
illustration. I would like to load the entire SWF in position, and
be able to change the attributes (i.e. colors) of individual
symbols (or parts of the illustration). I can load, display and
manipulate each symbol separately, but I need the parts to remain
in place.
The original art was created in Illustrator and exported as
SWF using the symbols palette.
I can always go back to Flash, but I'm forcing myself to move
forward and do this project in Flex (baptism by fire!!).
Is there some sort of dot notation to access the symbols from
within the SWF, without loading them all separately?
Let me put this another way: it appears that I can load an
SWF and then instantiate each symbol in that SWF, and then load
each symbol to the 'stage' (or whatever it's called in Flex)
separately.
I can certainly instantiate each symbol separately, and then
align it on stage, but it seems to me to be bass-ackward to do it
that way, expecially since I created the original SWF with
everything in position.
Is there no way to access the attributes of the individual
symbols within an SWF without separately instantiating them?
I'm just having trouble getting my head around this. Any help
is greatly appreciated.Okay, I took a look at this info and it's what I was already
doing.
Here's a simplified example of what I'm trying to do, using
the example in the swf9.pdf file.
Let's assume I've created a SWF with a "BlueSquare" movieclip
(in the symbols panel in Flash, exported for AS). In that clip,
there is another symbol called "Star". I import the SWF and
BlueSquare symbols in with the following code:
<mx:Script>
<![CDATA[
[Embed(source=”../assets/circlesquare.swf”)]
[Bindable]
public var LogoCls:Class;
[Embed(source=”../assets/circlesquare.swf”,
symbol=”BlueSquare”)]
[Bindable]
public var LogoClsBlueSquare:Class;
</mx:Script>
If I instantiate the BlueSquare on stage, it includes the
Star symbol when previewed, but I can't figure out how to get at
the Star symbol to change color. If I apply a color change to the
symbol, it changes the entire BlueSquare symbol.
If I instantiate the Star symbol separately, I can then
position it on the stage and make changes, but that requires
positioning it with actionscript. I'm trying to not have to
position a sub-element of my actual artwork because of it's
complexity.
I'd like to display the main movieclip (or sprite) with the
ability to access the attributes of a sub-movieclip or
sprite. -
How to access dynamic movie clips in a loaded swf
Hello,
I have a main movie file that loads a swf through loadclip.
There are several dynamic movie clips in the library of the
loaded swf (all set to export in first frame).
I'm trying to create a popup window (using the Window
component) by using code in the main movie to popup content that is
in a dynamic movie clip within the swf loaded by loadclip.
So far, I can create the popup without any problem as long as
the contentPath refers to a linkage identifier of a library item in
the main movie, but it won't work for a library item in the loaded
movie. Is there a way to make this work? Is there a special way to
reference library items in loaded movies?
Here's my code to create the window:
myWin = mx.managers.PopUpManager.createPopUp(this,
mx.containers.Window, true, {title:mytitle, contentPath:myref,
closeButton:true});
where myref is a string containing the linkage identifier for
the library item within the loaded swf.
Thanks in advance for any assistance,
JuliaI have found out that I can access a dynamic mc from the
loaded library (using attachMovie), but cannot use that same
dynamic mc as the contentpath for a popup window.
Any ideas why? -
Color external loaded swf in AS3 Help Urgent!
Hi i have loaded swf from an external path using the following command.
var cviewer:Loader=new Loader();
var curlRequest:URLRequest=new URLRequest("clipArts/"+evt.target.name);
So this is the scenario.
Suppose say i load Movie1.swf
I have three movie clips inside Movie1.swf called step0, step1, step2
I need to change the color of step0, step1 and step 2 from the parent flash file which loads movie1. All the inner movie clips color may be different from each other.
I am able to change the color of the whole movie clip by using
var colorInfo:ColorTransform = cviewer.transform.colorTransform;
colorInfo.color=evt.target.selectedColor;
cviewer.transform.colorTransform=colorInfo;
But not of individual ones. I even tried cviewer.step0.transform.colortransform and other stuff to see if it would work. But nothing worked. Help at fastest would be deeply appreciated.
Regards and thanks in advance.try:
var colorInfo:ColorTransform = MovieClip(cviewer.content).step0.transform.colorTransform;
colorInfo.color=evt.target.selectedColor;
MovieClip(cviewer.content).step0.transform.colorTransform=colorInfo; -
(AS3) Controlling Loaded SWF
I am trying to control a loaded .swf with the parent .swf. I
do not know how to call the loaded .swf. I know how to control the
parent with the child, but not the other way around. any
suggestions would be great. thanks!call on the Loader object where the movie is being held.
You'll need to typecast like this....
MovieClip(Loader.contentLoaderInfo.content). My recommendation is
to store that path to a variable
var myLoadedMovie:MovieClip = MovieClip(
varNameOfMyLoader.contentLoaderInfo.content);
change out the varNameOfMyLoader with the proper variable
name and you should be able to target the movieclip as you would
have done in AS2. -
Loading SWF giving Instance name as TimeLine
I'm Loading swf into a movieclip name main_mc. After
successfully loading it into main_mc. I had written a function to
get all children present in that movieclip(main_mc). It is getting
Children present in that, but every time it give [Object
MainTimeLine] as instance3 or sometime instance10. How can i
control instance name of maintimeline as it is randomly getting its
name.... I'm attaching code use in getting child and loading it...
Plz check if their any problem in code.
quote:
Clip=new Loader();
var urlRequest:URLRequest=new URLRequest("test.swf");
Clip.contentLoaderInfo.addEventListener(Event.COMPLETE,LoadingDone);
Clip.load(urlRequest);
private function LoadingDone(event:Event):void {
var _mc:MovieClip=event.target.content as MovieClip;
main_mc.addChildAt(_mc,0);
//if i trace the name of _mc movieclip... it will instance4
or instance10 randomly
trace(_mc.name);
showChildren(stage,0);
function showChildren(dispObj, indentLevel:Number):void {
for (var i:uint = 0; i < dispObj.numChildren; i++) {
var obj:DisplayObject = dispObj.getChildAt(i);
if (obj is DisplayObjectContainer) {
trace(padIndent(indentLevel), obj.name, obj);
showChildren(obj, indentLevel + 1);
} else {
trace(padIndent(indentLevel) + obj);
function padIndent(indents:int):String {
var indent:String = "";
for (var i:uint = 0; i < indents; i++) {
indent += " ";
return indent;
when loading is done suppose test.swf has one_mc movieclip
Children traced are like that...
quote:
main_mc [object MovieClip]
instance3 [object MainTimeline]
one_mc [object MovieClip]
[object Shape]
Can we solve this problem...you can't control the instance name of a main timeline. but
if you name everything else, the main timeline will be the only
object whose instance name starts with "instance".
Maybe you are looking for
-
Exporting a playlist and displaying song length of time
I tried exporting a song list as a text file from iTunes and opened it up in Excel. The format for length of time of a song is altered. Rather than displayed as 2:30 for example it gives you a series of numbers. It looks as if it gives you the number
-
ITunes no longer sees my iPad device
Every now and again iTunes ceases to recognose my iPad. I use an iMac, iPad, old MacBook and have Apple TV and Time Capsule. I set a reminder in Calendar to sync/backup my iPad every week with my iMac but every so often, it just doesn't work. I haven
-
I created HTML for a document and wanted to use it as HELP. When I open the index in Internet Explorer it takes me to the various topics and I can see everything I need to see in a nice format. HOWEVER, when I try to open it in Mozilla I get html cod
-
1 second media pending, random occur
CS5 on Win7 64Bit, 6.4GB RAM reserved for CS5, Quadcore 2.4, all data on internal HDD, all Cachefiles and other Data in Projectfolders. 1440x1080 (1.3333) Project, 25 fps, PAL, 48000Hz, 1.5hours duration, 69 different Objects, biggest 9.2GB, mpeg, m2
-
Importing freedesktop file associations into various file managers
I love light FMs that don't rely on HAL (or rather, don't rely on it AND don't make me mess around with XML files to get them working). But file associations in most of them are a pain. - ROX makes you set up associations one by one - So does tuxcmd,