Communicate between loaded SWF's
I have a base SWF, and I am loading a another SWF into a movieClip array... i need to communicate from the loaded SWF to the base SWF i tried _root but think this only goes to the root of the loaded movieClip any ideas?
This is what I tried:
on (release) {
_root.moveContent(2);
thanks in advance
Rich
_root always refers to the current _levels main timeline. your main swf is always in _level0. unless you load a swf into another _level, _root will always reference the main timeline of your main (or loading) swf.
you can reference the main timeline of the loaded swf by referencing the target movieclip into which the swf was loaded.
Similar Messages
-
Communicate between SWF & Global static vars
Sorry for my inglish...
I’m having some problems on getting full communication between loaded SWFs. I'm totally stuck and my timing is running.
Suppose the following scenario:
Father-SWF has his own class and loads A-SWF and B-SWF. A and B SWF has his own class and package. To exchange values and run functions between SWF, I’m using a Global class with public static vars. Some of this vars are function, example:
GLOBAL CLASS WITH STATIC VARS (com. with other class and package beetween SWF)
package scripts
public class GlobalAct
public static var mainStage:Object;
public static var myFuncGlobalA:Function;
public static var myFuncGlobalB:Function;
MAIN CLASS FATHER SWF
package
import flash.display.MovieClip;
import scripts.GlobalAct;
public class FatherClass extends
MovieClip
public function FatherClass():void
GlobalAct.mainStage
= this;
GlobalAct.
myFuncGlobal = myFunc;
public function myFunc():void
//some wird stuff
A_SWF CLASS
package
scripts
import flash.display.MovieClip;
import scripts.GlobalAct;
public class Layout extends
MovieClip
private var someMc:MovieClip;
public function Layout()
someMc
= new MovieClip();
someMc. addEventListener(MouseEvent.CLICK,
mouseFunc);
public function mouseFunc (evt:MouseEvent):void
GlobalAct. myFuncGlobalA ();
B_SWF CLASS
Similar to A-SWF class but with other kind of functions…calling “GlobalAct.myFuncGlobalB();” for example.
This works great, when I run Father-SWF, it load every SWF and functions run from SWF to SWF.
The problem happens when I load Father-SWF in another SWF. There is a MAIN-SWF with his own set os class and a Global static vars Class.
MAIN-SWF loads a SWF that will load Father-SWF into the MAIN-SWF.
WORKING
Father-SWF -> many SWF that could load other SWF
NOT WORKING
Main SWF -> SWF -> Father-SWF -> many SWF that could load other SWF
When this happens none of the Global functions seems to work. The other Global vars seems OK, only function vars seems not to work.
I only get the error: “TypeError: Error #1006: value is not a function. at scripts::Layout/ mouseFunc ()” when I try to click a button inside A-SWF.
Does I lose my Global reference when loading the Father-SWF in another SWF?
How can I make this bullet proof and generic for every situation?
What’s the best oop practice to communicate between class and SWF on AS3?I figured it out.
It's under the pop-up window. Select edit locations to select confirm. -
Dynamically loaded swf to communicate with MovieClip on the stage
I have a heck of time here with an issue. I have an xml document that when a certain button on the stage is clicked it loads it's corresponding external swf into an empty movieclip on the stage. This empty movie clip is a holder for all external swfs.
So what I'm trying to do is when an external swf is loaded that has buttons on it, I need those buttons to communicate with the main timeline and remove a mc that is on the Stage. I need the currently loaded swf(s) to be able to do this. So whatever the currently loaded external swf is that's loaded, I need it to talk to the main timeline. (I have quite a few external swfs that need to do this) So I imagine I need to somehow target the currently loaded external swf to get it to talk to the main timeline.
The code below in summary doesn't work but it doesn't give errors either. I don't pretend to know what I'm doing and I haven't been successful in searching for a solution to this particular issue. If someone could give me guidance or direct me to a solution. I'd so much appreciate it.
// main timeline object
var index:Object=this;
function loadComplete (e:Event) {
TweenMax.to(index.mcholder,1, {alpha: .5});
// add the current module to the mcholder movieclip by using addChild
index.mcholder.addChild(e.currentTarget.content);
(e.currentTarget.content as MovieClip).addEventListener("eventTriggered", startListener);
function startListener(e:Event):void {
var ext_swf:MovieClip;
ext_swf = e.currentTarget.content as MovieClip;
trace("external swf");
ext_swf.button1.addEventListener(MouseEvent.CLICK, talktomainswf);
function talktomainswf():void {
TweenMax.to(index.mc_thatsonthestage, 1, {x:1000});
// now we have the first load we set firstLoad to false
index.firstLoad = false;
function loadError (e:Event) {
trace("error");You can use the event dispatcher to communicate between external swfs and a main timeline,
like so:
//in an external swf
//Once loaded
function onLoadComplete(event:Event):void
//dispatch an event in the form of a string
dispatchEvent(new Event("Talk to Main Timeline"));
//On the Main timeline
//listen for "Talk to Main Timeline"
stage.addEventListener("Talk to Main Timeline", listenForCallsFromExternalFiles, true);
//if the event is heard, do this:
function listenForCallsFromExternalFiles(e:Event):void
trace("I heard ya, now do stuff...");
That's the basic idea anyways, I use it all the time.
hope that helps,
~chipleh -
I've created a 'plugin' SWF file in CS3 using actionscript 3.
The purpose of this file is to be included as a postroll in the
open source flash media player JW FLV/Media Player (
http://www.jeroenwijering.com/?item=JW_Media_Player).
I have heavily customized the media player libraries to do
various new things/alter how things worked, and now want to be able
to include the SWF file within this into a child sprite/movie clip.
HOWEVER, the problem lies in that the media player is written
completely in AS2, and therefore I have to use the MovieClipLoader
class to load in the SWF. Updating the source to AS3 isn't an
option unfortunatly, and downgrading the AS3 SWF to AS2 isn't an
option either, mainly due to the fact I've learnt AS3, not AS2, and
find it frustrating trying to find the AS2 equivalent to the AS3
methods I know.
The problem though lies in that MovieClipLoader does not like
my SWF at all. Initially I was presented with a load of sandbox
errors from when it was loaded in, which I then resolved so that no
security errors are produced. However, whenever I load in the clip,
the target sprite/clip is empty. I have gone through checking that
no errors occur on load, and it reports that the loaded SWF has
been initialized, yet I see nothing. Also, the code loading the SWF
is not at fault as it loads any other SWF (even another AS3 SWF
which just creates a rectangle) no problem.
Oddly enough, using the MovieClip.loadMovie method works in
one situation - when you load it into the root of the AS2 file.
When loading it into an empty movie clip, the same problem of a
blank clip occurs. The problem is not specific to the media player
either, as it happened in any AS2 file where I was testing how to
load in the AS3 SWF.
If it is of any use, the sandbox errors produced by the AS3
file when loaded into AS2 swf I had to resolve where to do with
stage access for getting the stage height and width, and a
Loader.content error when pulling out the BitmapData. These were
resolved via setting the allowed domains policy and eliminating any
reference to stage.stageHeight/With.
Does anyone have any ideas on how to solve this? The only
possible solution I've been able to think of so far since the AS3
swf won't display is to play with the LocalConnection class as
tests showed I can communicate between the AS2 and AS3 files, but
this would have to be a last resort, and is less than ideal when
there can be multiple instances of the player running (I would need
to use unique connection names for each instance so as to prevent
player A interacting with player B, and also as only one of the
players can listen on the connection at once).I have the component in the top level also,
I get this error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()[C:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\controls\BaseButton.as:615]
at fl.controls::LabelButton/draw()[C:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\controls\LabelButton.as:724]
at fl.core::UIComponent/drawNow()[C:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\core\UIComponent.as:1343]
at fl.controls::List/drawList()[C:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\controls\List.as:594]
at fl.controls::List/draw()[C:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\controls\List.as:474]
at .tree::TreeList/draw()
at fl.core::UIComponent/callLaterDispatcher()[C:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Component Source\ActionScript 3.0\User Interface\fl\core\UIComponent.as:1532]
I've checked the definitions for the tree component,
The LabelButton and List I don't have much control over.
I'm not sure how to fix this. The xml is correct and loads easily if it's in the root document.
The list component doesn't load the labels, It stops on the first one.
What do I do next? -
Hey,
Does anyone know how to pass a variable (string) from one swf
to another if there in separate html pages?
I assume I’d have to send the variable from the first
page and load it into the second but I don’t know what
functions or code I should be using. Any suggestions would be a
HUGE help.
Thanks
If it helps: I’m creating a log in and sign up sheet
that can be accessed from several sites. I’d like to record
which site the user has come from when they signup.
Thanksif they are open at the same time (for the same user), you
can use the localconnection class to communicate between the
two. -
How to unload externally loaded swf which contains 3D Carousel?
Hello to all
I am learning AS3 and have been taking on various tutorials found on the net. While learning about AS3 I came across a lesson on http://tutorials.flashmymind.com/2009/05/vertical-3d-carousel-with-actionscript-3-and-xml/ titled "Vertical 3D Carousel with AS3 and XML".
I completed the tutorial and all worked fine so I then wanted to load the swf into a existing project. The loading of the swf goes fine and when I unload my loader it is removed but only visually as in my output panel in flash CS5 I get an error as follows
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at carousel_c_fla::MainTimeline/moveCarousel()
this error repeats over and over again slowing my swf movie.
So does this mean my main flash movie trying to still play / find my unloaded 3D Carousel?
If so how do I unload remove all the AS3 that is trying to run from the 3D Carousel?
I have included the AS3 below from the tutorial page and I understand that this is what I have to remove to "break free" from the 3D Carousel swf when it is unloaded. This is where I am stuck as my knowledge of AS3 is limited - Can you guys / girls help?
//Import TweenMax
import com.greensock.*;
//The path to the XML file (use your own here)
// old var from tutorial - var xmlPath:String = "http://tutorials.flashmymind.com/XML/carousel-menu.xml";
var xmlPath:String = "carousel-menu.xml";
//We'll store the loaded XML to this variable
var xml:XML;
//Create a loader and load the XML. Call the function "xmlLoaded" when done.
var loader = new URLLoader();
loader.load(new URLRequest(xmlPath));
loader.addEventListener(Event.COMPLETE, xmlLoaded);
//This function is called when the XML file is loaded
function xmlLoaded(e:Event):void {
//Make sure that we are not working with a null variable
if ((e.target as URLLoader) != null ) {
//Create a new XML object with the loaded XML data
xml = new XML(loader.data);
//Call the function that creates the menu
createMenu();
//We need to know how many items we have on the stage
var numberOfItems:uint = 0;
//This array will contain all the menu items
var menuItems:Array = new Array();
//Set the focal length
var focalLength:Number = 350;
//Set the vanishing point
var vanishingPointX:Number = stage.stageWidth / 2;
var vanishingPointY:Number = stage.stageHeight / 2;
//We calculate the angleSpeed in the ENTER_FRAME listener
var angleSpeed:Number = 0;
//Radius of the circle
var radius:Number = 128;
//This function creates the menu
function createMenu():void {
//Get the number of menu items we will have
numberOfItems = xml.items.item.length();
//Calculate the angle difference between the menu items (in radians)
var angleDifference:Number = Math.PI * (360 / numberOfItems) / 180;
//We use a counter so we know how many menu items have been created
var count:uint = 0;
//Loop through all the <button></button> nodes in the XML
for each (var item:XML in xml.items.item) {
//Create a new menu item
var menuItem:MenuItem = new MenuItem();
//Calculate the starting angle for the menu item
var startingAngle:Number = angleDifference * count;
//Set a "currentAngle" attribute for the menu item
menuItem.currentAngle = startingAngle;
//Position the menu item
menuItem.xpos3D = 0;
menuItem.ypos3D = radius * Math.sin(startingAngle);
menuItem.zpos3D = radius * Math.cos(startingAngle);
//Calculate the scale ratio for the menu item (the further the item -> the smaller the scale ratio)
var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);
//Scale the menu item according to the scale ratio
menuItem.scaleX = menuItem.scaleY = scaleRatio;
//Position the menu item to the stage (from 3D to 2D coordinates)
menuItem.x = vanishingPointX + menuItem.xpos3D * scaleRatio;
menuItem.y = vanishingPointY + menuItem.ypos3D * scaleRatio;
//Add a text to the menu item
menuItem.menuText.text = item.label;
//Add a "linkTo" variable for the URL
menuItem.linkTo = item.linkTo;
//We don't want the text field to catch mouse events
menuItem.mouseChildren = false;
//Assign MOUSE_OVER, MOUSE_OUT and CLICK listeners for the menu item
menuItem.addEventListener(MouseEvent.MOUSE_OVER, mouseOverItem);
menuItem.addEventListener(MouseEvent.MOUSE_OUT, mouseOutItem);
menuItem.addEventListener(MouseEvent.CLICK, itemClicked);
//Add the menu item to the menu items array
menuItems.push(menuItem);
//Add the menu item to the stage
addChild(menuItem);
//Assign an initial alpha
menuItem.alpha = 0.3;
//Add some blur to the item
TweenMax.to(menuItem,0, {blurFilter:{blurX:1, blurY:1}});
//Update the count
count++;
//Add an ENTER_FRAME listener for the animation
addEventListener(Event.ENTER_FRAME, moveCarousel);
//This function is called in each frame
function moveCarousel(e:Event):void {
//Calculate the angle speed according to mouseY position
angleSpeed = (mouseY - stage.stageHeight / 2) * 0.0002;
//Loop through the menu items
for (var i:uint = 0; i < menuItems.length; i++) {
//Store the menu item to a local variable
var menuItem:MenuItem = menuItems[i] as MenuItem;
//Update the current angle of the item
menuItem.currentAngle += angleSpeed;
//Calculate a scale ratio
var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);
//Scale the item according to the scale ratio
menuItem.scaleX=menuItem.scaleY=scaleRatio;
//Set new 3D coordinates
menuItem.xpos3D=0;
menuItem.ypos3D=radius*Math.sin(menuItem.currentAngle);
menuItem.zpos3D=radius*Math.cos(menuItem.currentAngle);
//Update the item's coordinates.
menuItem.x=vanishingPointX+menuItem.xpos3D*scaleRatio;
menuItem.y=vanishingPointY+menuItem.ypos3D*scaleRatio;
//Call the function that sorts the items so they overlap each other correctly
sortZ();
//This function sorts the items so they overlap each other correctly
function sortZ():void {
//Sort the array so that the item which has the highest
//z position (= furthest away) is first in the array
menuItems.sortOn("zpos3D", Array.NUMERIC | Array.DESCENDING);
//Set new child indexes for the item
for (var i:uint = 0; i < menuItems.length; i++) {
setChildIndex(menuItems[i], i);
//This function is called when a mouse is over an item
function mouseOverItem(e:Event):void {
//Tween the item's properties
TweenMax.to(e.target, 0.1, {alpha: 1, glowFilter:{color:0xffffff, alpha:1, blurX:60, blurY:60},blurFilter:{blurX:0, blurY:0}});
//This function is called when a mouse is out of an item
function mouseOutItem(e:Event):void {
//Tween the item's properties
TweenMax.to(e.target, 1, {alpha: 0.3, glowFilter:{color:0xffffff, alpha:1, blurX:0, blurY:0},blurFilter:{blurX:1, blurY:1}});
//This function is called when an item is clicked
function itemClicked(e:Event):void {
//Navigate to the URL that's assigned to the menu item
var urlRequest:URLRequest=new URLRequest(e.target.linkTo);
navigateToURL(urlRequest);Hi Ned thanks for the reply,
Ok so I have a button in my main movie that loads the external swf
stop();
var my_loader:Loader = new Loader();
var my_btn:Button = new Button();
var my_pb:ProgressBar = new ProgressBar();
my_pb.source = my_loader.contentLoaderInfo;
my_btn.addEventListener(MouseEvent.CLICK,startLoading);
function startLoading(e:MouseEvent):void{
my_loader.load(new URLRequest("carousel.swf"));
addChild(my_pb);
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishloading);
function finishloading(e:Event):void{
addChild(my_loader);
my_loader.addEventListener("killMe",
killLoadedClip);
removeChild(my_pb);
function killLoadedClip(e:Event):void {
my_loader.removeEventListener("killMe",
killLoadedClip);
my_loader.unloadAndStop();
removeChild(my_loader);
Then I have a button in my loaded swf that closes the loader
This is spread over 2 frames
Frame1
function closeIt(e:MouseEvent):void {
parent.dispatchEvent(newEvent("killMe"));
Frame 2
back_btn.addEventListener(MouseEvent.CLICK, closeIt);
Frame 2 also holds all the code for the carousel
Thanks for your time and help in advance people ; ) -
Small Bug in Flash 8: loading swf that´s a vectorized image in many layers
Hi! There´s a small bug in flash 8. If you load a swf
that it´s a vectorized image in many layers, when you give it
an action in onLoadInit, like mc.onRelease, the mc don´t
"catch" that action. You can try loading an image (it works), a lot
of swf (it works), but with this kind of swf the actions onRelease,
onPress, etc... don´t work.
The
swf
I´ll make a different vectorized image to make it works
(if there is only one layer it works)Seems odd it will only run once. Usually if a cache problem
you get the same
results even when you update the movie or server scripts.
If it is
http:// it is not local even if from the browser
cache.
Verify the html is validated.
Check to see if this applies to all swfs. Create a simple
hello world swf
that connects to a JSP script that returns a simple value to
Flash. If that
seems to work, then the problem is in the JSP or
Actionscripting coding.
Check you can load the JSP script repeatedly using a direct
call to it on
the browser line using
http://.
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
"srikanth_s_india" <[email protected]> wrote
in message
news:e6obld$lfb$[email protected]..
> Thanks for the article link.
>
> I can't provide the URL as it is within our application
which requires
> logging
> in. However, one more interesting thing about it is that
it always works
> for
> the first time (in the browser/machine) but not from the
next time.
>
> My doubt is whether it is because of the caching? When
it loads for the
> first
> time, the HTML and SWF files load from our server and
hence are allowed to
> communicate with our JSP. However, when it loads the
subsequent times, it
> probably loads from the cache and hence considered as a
local file and not
> allowed to communicate with our JSP file which is on the
Internet.
>
> Can anybody tell me how to enable a local SWF file to
load SWF files from
> the
> Internet & access URLs from the Internet in Flash 8
pluggin?
> -
TypeError: Error #1009 (loaded SWF)
I'm pulling out my hair on this one!
I'm just starting a site (full-Flash site) using CS3 and AS3.
I'm pretty much accustom to the new AS3 changes. I built a rough
structure to make sure the way I wanted to set the site up would
work (loading in external SWFs, etc.). The tests worked.
Now, I'm going in to make some things real, and I'm getting
this error as soon as an external SWF loads in:
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
at test_fla::MainTimeline/test_fla::frame2()
I've tried narrowing it down, couldn't find the exact culprit
(had to remove every ounce of ActionScript before it started to
function again). So I started to rebuild that movie entirely --
cleared out the Library and deleted every layer. Didn't work.
Couldn't even add a stop(); action in Frame 1.
Then I started completely fresh File > New, rebuilt again.
I tested after every single change. I finally built it up to the
point where I first tested the original, and it worked. So, then I
added a couple more things tested again, and got the error again.
Ahh, so I removed EXACTLY what I had just added. Tested again. SAME
ERROR -- now it won't go away no matter what I remove!
Crazier yet is that I can still load in my other test SWF
files and they have actions in them, and they're set up the exact
same way -- but they work...
The whole site is new, so every SWF is CS3/AS3. I'm not even
doing anything crazy, so I'm getting pretty frustrated trying to
build an all AS3 site and I can't even do basic stuff....
I can upload/email the FLA files in question if anyone has
time to look...
Thanks,
BrandonWell, when I test the loaded SWF within the Flash environment
(by itself), it plays just fine.
Then, I try to play the root containing movie (both within
Flash and on the web server) and as soon as that section loads, is
when the error occurs.
I've tried tracing everything. even down to putting trace()
actions between every layer. Can't determine what causes it...
One thing I noticed (but I assume is a naming convention that
Flash uses), is in the error above you see "test_fla", well, lets
say I have these files:
test-container.fla
test-home.fla
I don't have a test_fla, but the error code refers to it
anyway... -
Can't target main stage from dynamically loaded swf...
A part of the Flash app. I'm working on right now does the following -
Main stage loads an external swf using the following function:
function loadAsset(evt:String):void{
var assetName:String = evt;
if (assetName != null){
var assetLdr:Loader = new Loader();
var assetURL:String = assetName;
var assetURLReq:URLRequest = new URLRequest(assetURL);
assetLdr.load(assetURLReq);
assetLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)
assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);
function loaded(event:Event):void {
var targetLoader:Loader = Loader(event.target.loader);
assetWindow.addChild(targetLoader);
The externally loaded swf loads another external swf into itself using the following function:
function loadQuiz(evt:String):void{
var quizName:String = evt;
if (quizName != null){
var quizLdr:Loader = new Loader();
var quizURL:String = quizName;
var quizURLReq:URLRequest = new URLRequest(quizURL);
quizLdr.load(quizURLReq);
quizLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)
quizLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayQuizLoaderProgress);
function loaded(event:Event):void {
var targetLoader:Loader = Loader(event.target.loader);
quizWindow.assetLoader.addChild(targetLoader);
Everything loads fine, but from the quizWindow.assetLoader.addChild(targetLoader) level, I want to send a message/fill in a dynamic text box on the Main Stage. I have been "parenting" my brains out and I'm not sure how to communicate with that level.
can anyone show me the proper path or method based off the above, or have a suggestion?
Cheers,
~ChiplehAndrei1,
Thanks again for your help. I was finally able to get the solution you posted below to work for me.
Much appreciation,
~Chipleh
"In your loaded movie write:
function traceMyself(e:MouseEvent):void{
dispatchEvent(new Event("I_WANT_TEXT"));
function writeText(text:String):void {
xmlFileName1.text = text;
In the top movie that loads external swfs something like that:
loadedSwf.addEventListener("I_WANT_TEXT", onTextRequest, true);
function onTextRequest(e:Event):void {
Object(e.target).writeText(tQuizXmlFile1.theQuizXmlFile.text);
This way these two entities are independent and, most importantly, don't care who is the parent or grandparent." -
As 3 load swf flie problem,help
I have now trapped by a strange problem of loading the swf
file.For some reason I need to use a main swf file to load other
swf file and use the class in it,it's very common.
And now I worte a class blow to explain what problem I met:
package
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class TestClass extends MovieClip
public var sp:Sprite;
public static var count:Array=new Array();
public function TestClass()
sp = new Sprite();
//drawcrr();
this.addEventListener("test",test);
count.push("");
trace("count in circle is:", count.length);
private function test(e:Event):void
drawcrr();
public function drawcrr():void
sp.graphics.beginFill(0);
sp.graphics.drawCircle(0,0,10);
sp.graphics.endFill();
addChild(sp);
Save it as TestClass.as for next use;
Use the class to link to a fla file as the documentClass then
compile as a swf file name as
kk.swf then make a copy name kk1.swf;
Create a new fla file in the same directory then write the
code blow on the mainTimeLine :
var kk:TestClass = new TestClass();
var URL1:URLRequest = new URLRequest("kk1.swf");
var URL2:URLRequest = new URLRequest("kk.swf");
function domain():LoaderContext
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new
ApplicationDomain(ApplicationDomain.currentDomain);
return context;
var L1:Loader = new Loader();
L1.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
L1.load(URL1);
var L2:Loader = new Loader();
L2.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
L2.load(URL2);
//v.text = flash.system.Capabilities.version;
function onComplete(e:Event)
trace(e.target)
then compile this fla file you will find the flash will put
out below:
count in circle is: 1
count in circle is: 2
count in circle is: 3
[object LoaderInfo]
[object LoaderInfo]
and if you notation the line "var kk:TestClass = new
TestClass();" compile it again
the flash will output :
count in circle is: 1
count in circle is: 1
[object LoaderInfo]
[object LoaderInfo]
It's prove that the same class in the different swf was
loaded by a main swf file,the same class in the different swf file
will be treated as the different class so that I can use them
individually but when I put the code:"var kk:TestClass = new
TestClass();" in the main swf file all this will be break down,I
can't use the class in kk.swf and class in kk1.swf individually
the flash make then as the same class because the static
variable "count" was count to 3.
it prove that all those 3 swf file will use the exactly same
class;So, that's the problem,it will make my programme cause error.
Can some one kindly to tell me why this happened?And how can
I solve this problem.Sorry about that.
That problem is:
If I use a shell swf to load some swf file and the shell swf
and the loaded swf file have the same name class,The loaded swf's
class will be ignored.
That will make me can't use the loaded swf file's class which
have same name with the shell swf.
However, this problem can be solved by useing the application
domain.Just give the swf you loaded a new application domain in the
shell swf.
But after that I found a new problem appear in front of mine,
that is:
If I use the different application domain in my shell swf how
could they communicate with each other?
For example:
If my shell swf have a class named TEST,and the loaded swf
also have the same name class those two classes both extends the
class named TESTParent and the TESTParent have a public static
variable to count the instance of the class.If I want use those two
TEST
class individually and at the same time made the static
variable in the TESTParent count work as a same class how can I do? -
Controling objects in a loaded swf at any given time
I want to communicate with an object within a loaded swf. I know I can use this event listener and function to do so right when the swf has completed loading:
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadSections)
function loadSections(event:Event):void
event.target.content.mc.y+=2
But I want to be able to manipulate a given object from the loaded swf at any time not just when the loading is complete. So basically as long as the swf is loaded, is there a way to manipulate objects and call functions within that swf?
Both the external and host swf are AS3.
ThanksI'll just try to add to what Ned already told you.
IF (and only if) I understood what you're trying to do, all you want is press a button to load a new SWF and then click the loaded swf to unload it, right?
If this is what you want, I think you have to understand that a loader IS a displayObject and it CAN be added to the displayList. It took me a lot of time to understand this so maybe this is where you're having trouble to "think" your application (and I guess it is because you're using holder.addChild(imageLoader);, which is not wrong).
Since a loader is a displayObject that can be added to the displayList, you don't really need a another displayObject do hold it, like a holder.
You can simple use addChild(imageLoader);
Doing so, you will have a "loader" on stage working just like anyother displayObject. You can add listeners to it, you can remove it from stage, change its location and all.
So, as Ned said, when you add a loader to the stage, if you want to remove it, go ahead an remove it!
removeChild(imageLoader);
//or, in your case:
holder.removeChild(imageLoader);
The only thing here (as far as my knowledge goes) is that the loaded content still exists EVEN if it doesn't exist on the displayList anymore. That's why you MUST unload it TOO.
imageLoader.unload();
Doing so you'll send the loader content for GarbageCollection and this will be deleted when more memory is needed.
Another best practice I've noticed is that you should avoid from "creating" a loader from withing a function.
Well, just to give you an idea of what you can do:
import flash.events.MouseEvent;
var req:URLRequest = new URLRequest("external.swf");
var loader:Loader = new Loader();
//A button we have on the timeLine.
myBtn.addEventListener(MouseEvent.CLICK, onClick);
function imageLoaded (e:Event):void {
addChild(loader);
loader.addEventListener(MouseEvent.CLICK, unloadAndRemove);
trace (loader is DisplayObject);
function unloadAndRemove (e:MouseEvent):void {
e.target.unload();
removeChild(loader);
function onClick(e:MouseEvent):void {
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(req);
I hope it helps. -
Load SWF file in main SWF with parameters
Hello everybody,
I recently got a new flash Application which is a Photo Gallery.
This App is made of multiple folders (source files), a FLA file, a SWF with its javascript SWFObject and an Html page which instantiate this App with some parameters (size, config file path, ...).
It needs an XML file to find all the Photos it displays, to do it I need to configure my application in the HTML Page and give it the "xml_path" :
var so = new SWFObject("index.swf", "gallery", "249", "249", "10", "#111111");
so.addVariable("xml_path","load/config.xml"); // this line is adding the path to the xml file make sure that it's name is xml_path
so.addParam("allowfullscreen","true");
so.write("flashcontent");
By the way, I have a second application, the WebSite, which have to display the Gallery SWF in its "Gallery" page.
Here is how I do it at the moment (in ActionScript3) :
var swfRequest:URLRequest = new URLRequest("C:/......../Galerie/index.swf");
var swfLoader:Loader = new Loader();
//Charge le SWF Galerie dans le SWF Site
swfLoader.load(swfRequest, context);
container1.addChild(swfLoader);
//Positionne le SWF
swfLoader.x=10;
swfLoader.y=120;
It successfully loads the Gallery application but It shows an error telling me it doesn't find the XML configuration file... In the HTML file I simply had to write the "so.addVariable("xml_path","load/config.xml");" to tell where the XML file is...
So, my question is : How can I integrate my SWF application giving it some parameters like above, in Action Script 3?
Thank you ,
PatrickNo, nothing with HTML.
I have 2 SWF applications. One is the Gallery, and the second is my Main Page.
My Main Page must integrate the Gallery module in one of its page.
The problem is when I try to integrate it, I think I must give de future loaded SWF some parameters like this :
(My Main SWF loading in HTML)
var so = new SWFObject("WebSite.swf", "flashcontent", "520", "700", "10", "#111111");
so.addParam("allowfullscreen","true");
so.addParam("allowScriptAccess","always");
so.addParam("menu","false");
so.addParam("wmode","opaque");
so.addParam("bgcolor","#000000");
so.setAttribute("id","flash");
so.write("flashcontent");
It was for the Main App. For my Gallery SWF I had to load it like this (in HTML) :
var so = new SWFObject("Gallerie.swf", "gallery", "249", "249", "10", "#111111");
so.addVariable("xml_path","Galerie/config.xml"); // this line is adding the path to the xml file make sure that it's name is xml_path
so.addParam("allowfullscreen","true");
so.write("flashcontent");
So at the beginning I had 2 different projects with an HTML page for each.
Now I wan't to directly integrate the Gallery SWF into the Main SWF. And as you have seen I must give it some parameters such as the "xml_path" and "allowfullscreen". This must be done in ActionScript 3 and I don't know how...
I think I have to use FlashVars but I don't know how. As I said before, I have tried using the loaderinfo.parameters, but it is in read-only...
Do you have an idea of how I can make it work ? -
Using TextSnapshot class on a loaded SWF on an iPad
Hello, I am creating an iPad app. I am loading SWF files using a Loader object, then placing them in a movieclip and setting a SWFLoaders source property to this clip. Before I add the clip to the SWFLoader control I am using the TextSnapshot class on it, to retrieve an array with the getTextRunInfo method.
All this works fine when I test it on my desktop machine. However, on the iPad it causes the app to crash when a control using this clip is added to the stage. Can you still use TextSnapshot with an iPad, is there a workaround for this? Thanks for your help.We are a university. most of our books are SWF files. We have been using iPad/FlexBuilder 4.5 to successfully view the contents of these books.
All navigation (i.e gotoandstop(page), etc work fine. Gestures for pageforward/pageback, zoom, pan work fine also.
Not sure I understand your comment.
However, there IS a specific problem with text snapshot. Below is a short code piece used to highlight text on a page.
If you remove the failing line everything works fine.
If you "debug" the iPad device everything works fine when you execute the code on the iPad
if you create a release build, when the application starts and the "findtext" line is executed the "app" freezes. No error message. The try/catch does not seem to catch any error.
This is something we really need for our app. If this is a bug how should we report it.
Thanks for your help.
public function highlightText(txt:String):void {
var start_pos:int = 0;
try {
if (txt == null || txt.length == 0) { return; }
infoMessage("highlightText: " + txt);
allText = _libMC.textSnapshot;
allTexts.push(allText); // no reason for this but must do to make work
start_pos = allText.findText(start_pos, txt, false); <<<<<< Failing line ====================================
infoMessage("start_pos: " + start_pos);
catch (err:Error) {
infoMessage("error: " + err.message);
finally {
infoMessage("finally"); -
ipad i have load swf file but swf is not working proper(flex 4.6) but android is fine to work how
On the MBP, in iTunes, switch to Song view and enable the iCloud Status column by pulling down View > View options and selecting the option for "iCloud Status." Close the small window. Look for any tracks that have a status of "waiting." If you see several of them disable iTunes Match while holding down the Option key. Quit iTunes, wait a few seconds, then open it again and turn iTM back on. Let it compelete the scan. Wait until all tracks that are "waiting" have a status of either "matched" or "uploaded."
On the iPad, turn off iTunes Match then launch the Music app and let the contents clear out. Power cycle the iPad for good measure, then re-enable the service once all the tracks in iTunes have been processed. -
Hi all,
A customer has a large PC application developed with LabVIEW 2010 SP1.
They would like to add extend their system with a cRIO-9075. According to this document (ftp://ftp.ni.com/pub/devzone/tut/crio_software_versions.htm ), the minimum supported version of LabVIEW (with Scan Engine support) is LV 2011.
To minimize risks, it is preferred that we don't upgrade LabVIEW for the main application, which is atively being used in production.
I was thinking of developing the cRIO software in a newer version of LabVIEW (say, LV 2013 SP1), and using shared variables only to communicate between the PC and the cRIO.
Is this a viable option? Does it matter if the PC and the cRIO have different versions of the LV runtime?It shouldn't matter, but then with shared variables you can never know for sure -- there are so many things that can make them break.
You might be money ahead to write the comm using TCP/IP. You know that will work.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
Maybe you are looking for
-
Lion Server network accounts not working on some computers.
Hello all - I'm currently having an issue with network accounts working on some Macs but not others. I have a Mac Mini and a MacBook Pro. The Mac Mini works fine and I can login and sync my network account with the server just fine. However, I cannot
-
Hi All, I am trying to create a tab delimited file using Sender File adapter using <b>File content Conversion in Adapter Module</b>. I want a constant space beteween the fields of length 8 spaces. When i use ' ' as field seperater , t
-
I can get the camera working for Skype but face time is fine ??
Hi I ahve a brand new 13" pro retina mac book and all of a sudden my skype wont activate the camera the green light doesn't go on but it works fine for face time so its not a hardware issue. I have checked the photobooth and face time is off so not s
-
Post Processing array for moving average
Greetings. Hope someone out there can help me on this. I have read all the posts I could find about doing a moving average and they all had to do with performing it as the data is being acquired. Unfortunately, I can't do that. I am getting the data
-
How can I create a reserve invoice with DI API?
HI, I need to create a reserve invoice with DI API, how do I this?. I have SAP B1 2005A. Sorry for my english. Thank's.