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
Similar Messages
-
TotalFrames of dynamically loaded swf
I've been trying for 2 days now to find the total number of frames of a dynamically loaded .swf.
Here's an example code:
var loader:Loader = new Loader;
loader.load(new URLRequest("mop.swf"))
master_mc.addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, xmlLoadedF);
function xmlLoadedF(event:Event):void
trace(loader.content.totalFrames);
I am truly puzzled.
Any help would be greatly appreciated.I think this might be complicated by loading an AS2 movie into an AS3 document.
The error message is telling you that there is no totalFrames property and in fact AS2 movies would have a _totalframes property.
So you could try that.
Also I'm not sure if event.currentTarget.content returns a MovieClip or a DisplayObject. If it is a DisplayObject (which is most likely) then it too wouldn't have totalFrames property. So you might need to cast it as a MovieClip. Something like this:
MovieClip(event.currentTarget.content).totalFrames
And or it could be some combination of these two above issues? I don't know really, I'm just grasping at straws. But I don't see any way to know when a clip is done playing other than to compare its currentFrame to totalFrames. -
Alpha transparency borders on dynamically loaded images for use with textures
Hi there folks. Well, I have been beating my head over this
and am hoping one of you can help me out.
Essentially I have 16bit images that are loaded into my
shockwave application at run-time. These images are user defined
which means that I will not know their size ahead of time. Once the
images are loaded I then create textures and apply them to various
shaders. Ok, all of this works just fine. What I need to do though
is create an alpha transparent border around the images, so when I
apply them to their surfaces I only see the image and nothing
around it. I am doing this because these images will only appear at
specific parts on a surface, textureRepeat will be false, and many
models will be stacked in the same exact location using the same
model resource. I have everything working, but I cannot figure out
the alpha part for the life of me. Also, when I test the alpha
based image by itself it works just fine. It is not until I try and
combine the 16bit (converted to 32bit at run-time) image that I run
into problems.
I have tried:
- Creating a 32bit alpha image in Fireworks with a
transparent border and a black rect for the inside. I then copy the
dynamic image over the alpha image (only after going from 16bit to
32bit in imaging Lingo) and leave a little room at the edges for
the transparency. Well, I get a crazy amount of streaks here even
when I try to up the trans border by around 24 pixels on each side.
- Using another similiar alpha based image as a mask with
copyPixels and extractAlpha/setAlpha like this... (code is a little
rough here)
newImage = new(#bitmap)
newImage.name = "place_Test"
newImage.image = member("place").image
newAlpha = new(#bitmap)
newAlpha.name = "AHH"
newAlpha.image = image(newImage.image.width + 24,
newImage.image.height + 24, 32)
newAlpha.image.useAlpha = true
newAlpha.image.copyPixels(member("vase").image,
newAlpha.image.rect, member("vase").image.rect)
newAlphaInfo = newAlpha.image.extractAlpha()
newAlpha.image.useAlpha = false
--reverse dark to light
iAlphaReverse = image(newAlpha.image.width,
newAlpha.image.height, 8, #grayscale)
iAlphaReverse.fill(iAlphaReverse.rect, rgb(0,0,0))
iAlphaReverse.copyPixels(newAlphaInfo, iAlphaReverse.rect,
newAlphaInfo.rect, [#ink : #reverse])
--newAlphaInfo.copyPixels(iAlphaReverse, newAlphaInfo.rect,
iAlphaReverse.rect, [#ink:#subtractpin])
newAlphaMask = iAlphaReverse.createMask()
rescaleAbs(newImage, newImage.image.width,
newImage.image.height, "place_Test", 32)
destImage = member("place_Test").image.duplicate()
destImage.fill(destImage.rect, rgb(0,0,0))
newAlpha.image.useAlpha = false
destImage.copyPixels(newImage.image, newImage.image.rect,
newImage.image.rect, [#maskImage:newAlphaMask, #ink:#add])
destImage.setAlpha(iAlphaReverse)
destImage.useAlpha = true
member("place_Test").image = destImage
I apologize for the messy code. I have cut and pasted from
all over the place and am getting confused. In any case, I think I
am making this harder then it needs to be and hope someone can
help.
Thank you in advance,
DaveHi, you can try using other texture layer as mask on the same
shader. As usually you create the texture from a dynamic loaded
image, then apply this texture to the shader on the texture list
index 1 (textureList[1]). Next part does the job, create other
texture from a 32 bits image with the alpha information and fill
all pixels with white color, this is very important because the
second texture layer will be multiply with the first texture layer.
This texture set its render format to rgba8888. Apply the mask
texture to the same shader at texture list index 2, verify that the
blendFunctionList index 2 is #multiply.
I include the code of a project that use this masking
approach:
property pMember
property pEarthSphere
property pNightSphere
property pLastTransform
on beginSprite me
pMember = sprite(me.spriteNum).member
me.setupWorld()
end
on setupWorld(me)
pMember.resetWorld()
repeat with i = pMember.light.count down to 1
pMember.deletelight(i)
end repeat
vEarthModelResource = pMember.newModelResource("EARTH MODEL
RESOURCE", #sphere)
vEarthModelResource.radius = 50.000
vEarthModelResource.resolution = 20
vEarthTexture = pMember.newTexture("EARTH TEXTURE",
#fromCastMember, member(3,1))
vEarthShader = pMember.newShader("EARTH SHADER", #standard)
vEarthShader.emissive = color(255,255,255)
vEarthShader.flat = TRUE
vEarthShader.transparent = FALSE
vEarthShader.textureList[1] = vEarthTexture
pEarthSphere = pMember.newModel("EARTH MODEL",
vEarthModelResource)
pEarthSphere.shaderList = vEarthShader
vNightModelResource = pMember.newModelResource("NIGHT MODEL
RESOURCE", #sphere)
vNightModelResource.radius = 50.2000
vNightModelResource.resolution = 20
vNightTexture = pMember.newTexture("NIGHT TEXTURE",
#fromCastMember, member(4,1))
vNightTexture.quality = #lowFiltered
vNightTexture.nearFiltering = FALSE
vNightTexture.renderFormat = #rgba8880
vNightShader = pMember.newShader("NIGHT SHADER", #standard)
vNightShader.emissive = color(255,255,255)
vNightShader.flat = TRUE
vNightShader.transparent = TRUE
vNightShader.textureList[1] = vNightTexture
vMaskNightTexture = pMember.newTexture("MASK NIGHT TEXTURE",
#fromCastMember, member(6,1))
vMaskNightTexture.renderFormat = #rgba8888
vNightShader.textureList[2] = vMaskNightTexture
vNightShader.textureModeList[2] = #wrapPlanar
pNightSphere = pMember.newModel("NIGHT MODEL",
vNightModelResource)
pNightSphere.shaderList[1] = vNightShader
pNightSphere.parent = pEarthSphere
end
on exitFrame(me)
pEarthSphere.rotate(0.0,0.1,0.0)
me.moveMaskNightTexture()
end
on moveMaskNightTexture(me)
vRotationVector = - pEarthSphere.transform.rotation
pNightSphere.shaderList[1].wrapTransformList[2].rotation =
vRotationVector
end -
Loading/Unloading a .swf that adds event listeners to the Stage
Hi all,
Disclaimer
Apologies if I suck so bad at using forum search that the answer to this is on page 1 somewhere; I tried...
Question
I am loading and unloading a .swf to which I do not have source code access. This .swf places several event listeners on the stage, as far as I can tell. When the .swf is unloaded, the event listeners placed upon the stage still seem to be in effect. Using unloadAndStop doesn't seem to do it, and I have to target Flash Player 9, anyway, so can't really use it. Is there any other way I can keep this external .swf from holding onto my main movie's stage?
Additional info
All eventListeners and references being set by my code are removed.
I've managed a little contact with the author of the .swf:
I've requested he provide a dispose() method I can call to get all the listeners removed, and send an updated .swf.
He's suggested that I should be able to avoid the problem by loading into a unique ApplicationDomain. I'm not terribly familiar with this, but have given it a try without much success. Is this a valid solution - can I really protect my 'stage' by properly using ApplicationDomains - or do I need to persist in trying to get a public dispose() method built in?
Thanks in advance!
Cheers, Johnthanks for reply sir
sir actually, i have not any problem with loading any file but i need to go back to intro.swf file when i click on clsbtn of main.swf, i want unload the main.swf file and panel.swf file
actually i did was, i have intro.swf file and there is button by clicking load main.swf file (where is timeline controling butons) and in the main file automatically load panel.swf file ( where is all animation)
its all play gud , no problem
but my problem is there is a clsbtn in main.swf file and when i click on that button everything should be unload and it should return on the previous position in intro.swf
i hope u understand what i am trying to say -
I can't connect to iTune Store nor to radios, with the aid of iTune,check for updates, these last two from aid, but if you communicate with support.Please the answers in spanish.
Back up all data.
Unlock the Network preference pane, if necessary, by clicking the lock icon in the lower left corner and entering your password. Cllck Advanced, open the DNS tab, and change the server addresses to the following:
8.8.8.8
8.8.4.4
That's Google DNS. Click OK, then Apply.
In Safari, select
Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
and confirm. If you’re using another browser, empty the cache. Test. Any difference?
Notes:
1. If you lose Internet access after making the above change to your network settings, delete the Google servers in the Network preference pane, then select the TCP/IP tab and click Renew DHCP Lease. That should restore the original DNS settings; otherwise restore them yourself. Remember that you must click Apply in order for any changes to take effect.
2. I don't use Google DNS myself, though I have tested it, and I'm not recommending it or any other DNS provider; the server addresses are offered merely for testing purposes. There may be privacy and technical issues involved in using that service, which you should investigate personally before you decide whether to keep the settings. Other public DNS services exist. -
I'm moving to Japan and will be bringing my iPad, will FaceTime work to communicate with friends in the USA?
As long as you both have Wi-Fi.
-
TypeError: Error #1006 - Removing MovieClip from the stage
I have a movie clip that is called to the stage and once the movieclip is finished it calls a function that removes it from the stage. The code works but I get an error message about 4 seconds after the movie clip ends.
Here’s the error message:
TypeError: Error #1006: exitWordMicroscopic is not a function.
at ASvocabulary_microscopic/frame110()[ASvocabulary_microscopic::frame110:1]
Here’s the stage code:
//************************Removes the movieclip from the stage and enables the button.*************************
function exitWordMicroscopic():void
bnt_vocab_microscopic.mouseEnabled = true;
removeChild(word_Microscopic);
//******************************Stage buttons**************************************
stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);
function goButtonsHomeRead_1(event:MouseEvent):void
//Vocabulary buttons
if (event.target == bnt_vocab_microscopic)
bnt_vocab_microscopic.mouseEnabled = false;
SoundMixer.stopAll();
addChild(word_Microscopic);
word_Microscopic.x = 47;
word_Microscopic.y = 120;
Here’s the code inside the movie clip. This is what the error message is referring to:
//****************** Calls function to remove itself from the stage****************************
Object(parent).exitWordMicroscopic();
What am I doing wrong?Here' how the code looks now:
Objective: To remove the current movieclip while it's playing so that it does not show on the next (or previous) frame.
Here’s the stage code:
var word_Microscopic:ASvocabulary_microscopic = new ASvocabulary_microscopic();
//Removes the movieclip from the stage and enables the button.
function exitWordMicroscopic():void
bnt_vocab_microscopic.mouseEnabled = true;
removeChild(word_Microscopic);
//******************************Stage buttons**************************************
stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);
function goButtonsHomeRead_1(event:MouseEvent):void
//Vocabulary buttons
if (event.target == bnt_vocab_microscopic)
SoundMixer.stopAll();
bnt_vocab_microscopic.mouseEnabled = false;
addChild(word_Microscopic);
word_Microscopic.x = 47;
word_Microscopic.y = 120;
word_Microscopic.play();
//This button takes the user to the Main Screen
if (event.target == bnt_ReadGoHome_1)
// exitWordMicroscopic(); [If I use this function I get this error ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.]
SoundMixer.stopAll();
gotoAndPlay("1","Main");
stage.removeEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);
//This takes the user to the next frame.
if (event.target == GoNext_1)
SoundMixer.stopAll();
gotoAndPlay("2");
stage.removeEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);
Here’s the code inside the movie clip.
//****************** Calls function to remove itself from the stage****************************
Object(parent).exitWordMicroscopic(); -
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." -
IE Active Content + Dynamically Loaded Swfs...any help?
Hi,
I've recently become aware of the whole IE active content
problem and I followed the tutorial at
http://activecontent.blogspot.com/
to adjust my html files accordingly. However I have one site
located at:
http://www.mrdodson.com/SavannahSucks/SavannahSucks.html
which loads several swfs dynamically. However in IE none of the
swfs will start loading until you click on one of the markers
which, unfortunately locks the user into a zoomed in view with no
way of exiting until the external file finishes loading. Can anyone
provide any suggestion on how I can get around this? Should I load
the clips in a different fashion or can it be resolved by adding
something to the HTML? I'm a recent grad trying to finish up my
portfolio and this is really holding me back. Many thanks for any
suggestions.
-Robplease if anyone knows anything i would really appreciate it.
i can't send my portfolio out until i fix this one thing so pretty
much my life is on hold until i can resolve this. -
Dynamically loaded .swf missing it's mark
I have had a website that has been up and successfully running for about a year now. Admittedly, it's a little buggy here and there, however - I have not had too many issues with it to date.
Recently, however, I updated the main / root .swf slightly - just changed some copy, and added a slide or two throughout. When visiting the site, this main .swf dynamically loads any content .swfs required - the html, and these .swfs were not touched.
Upon uploading the new main .swf only - everything works fun, until it loads one of the content .swfs - this always loads in the top left of the browser, rather than the center top of the browser.
Does anyone have an idea what could be causing this - it just seems odd as I touched no code at all.
Thanks in advance!Nope - the main .fla / .swf is in the correct position. The html calls it to be top / centered.
When "that" file dynamically loads an additional .swf - they are all going up and left - off center from the site entirely. Seems odd, I've checked the placement as3 - everything seems to be in order. Any ideas? Could this just be a small bug somewhere changing something enough to do this? -
HP Officejet 6700 Premium. Using McAfee. Vista Home Premium. Trying to set it up as a network printer. The computer can't communicate with the printer through the router, and I think it has something to do with the McAfee firewall.
Hello gtilghman
Please try the HP Network Diagnostic Utility. It should help you setup your printer on the network.
Don't forgot to say thanks by giving "Kudos" to those that help solve your problems.
When a solution is found please mark the post that solves your issue. -
Hello,
I am using the ActionScript 3 in a aplication and i have
problem to access the MovieClips that is on the Stage. Let me
explain.
I the stage i have two MovieClips, with instance of mc1 and
mc2. Inside of mc1 i try to access some proprerties from mc2 but
without success.
I try using this:
trace(parent.mc2.width);
But the Flash return the error 1119, undefined propertie.
So, how can i access the MovieClips that is on my stage from
another MovieClip.
Thanks:
-
Placing movieclips on the stage
Hello,
I am trying to place movieclips from the librari on the stage
but i only get one row.
This is wat i want to archieve. (for example M = a
movieclip).
M M M M M M
M M M M M M
M M M M M M
M M M M M M
If i also fill in the _y the result looks like this.
M
.. M
..... M
........ M
............. M
now it looks like this:
M M M M M M
This is the code i used:
var tegelhouder:MovieClip =
this.createEmptyMovieClip("tegelhouder",
this.getNextHighestDepth());
tegelhouder._x = -70;
tegelhouder._y = 0;
for(i=1; i<9; i++) {
tegelhouder.attachMovie("tegelanim", "tegels"+i, i);
tegelhouder["tegels"+i]._x = i*70;
So the first thing i am trying to archive is to place the
movieclips vertical as horizontal.
Can someone help me with this?
Regards,
Micheal//this is very simple
//All is you need them in rows one by one
//do this
for (var a:Number = 1; a<=30; a++) {
attachMovie("dd", "dd"+a, a);
//if you want them in 5 clips in a row then
trace(a%5);
if (a == 1) {
// to place the first one at some point
_root["dd"+a]._x = 100;
_root["dd"+a]._y = 100;
} else {
if (a%5 == 1) {
_root["dd"+a]._y =
_root["dd"+(a-1)]._y+_root["dd"+(a-1)]._height+2;
_root["dd"+a]._x = 100;
} else {
_root["dd"+a]._y = _root["dd"+(a-1)]._y;
_root["dd"+a]._x =
_root["dd"+(a-1)]._x+_root["dd"+(a-1)]._width+2;
Hope you enjoy -
I've got a movieclip animation which is added to the stage at the start of the .swf. Its an introduction to the game, and the user is encouraged to click on the movieclip to start the animation.
Once the animation is finished I'd like the movieclip to be removed from the stage.
How do I go about doing this? Do I need to setup some sort of event handler which listens out if the movieclip has finished then start a function once its finished to remove it from the stage? Which methods look out for movieclips finishing?
Cheersthere is no specific event that's called when a movieclip stops playing,
what you could do is inside your intro movieclip dispatch an event as soon as the animation is finished
something like ... dispatchEvent(new Event("introFinished");
and all you have to do is add and event listener to the intro movieclip intro.addEventListener("introFinished", onIntroFinished);
when your onIntroFinished is called you can remove the intro from the stage. -
Allow loaded swf's communication with the internet
Hi,
I have an air application that is loading in swfs, the swfs then intern request data from internet.
For example I have one swf thats loaded into the air application that requests data from the flickr api.
But I keep getting adobe air security pop ups. "adobe air has stopped a potentially unsafe operation tring to comunicate with this internet-enabled location:
This application is going on a kiosk of types. Is it possible to add some sort of text file to the machines that has predetermined list of allowed internet-enabled locations so that this pop up doesnt keep appear and the application works with out us having to manually set each kiosk to allow a location?
Thanks
AidanHave you found an answer for this. I am running into the same
problem.
Maybe you are looking for
-
Hi experts, I am getting dump in J2IUN tragation ...dump analysis in st22 is as fallow Runtime Errors DYNPRO_FIELD_CONVERSION Date and Time 31.10.2007 14:02:22 Short text Conversion error What happened? The current screen processing
-
Data settings changing on their own and losing connection
Can someone tell me why when on PAYG with the payandgo.o2.co.uk setting does it change back on it's own to idata.o2.co.uk and then my internet connection is lost and when I try and change it back to payandgo.o2.co.uk half to time it doesn't stick, so
-
I am using Communicator Pro with Enterprise Calendaring, Calendar client 4.6, and when I attempt to launch it I immediately get a core dump and it does not launch. <P> The 4.6 motif client is not able to run against the 4.0 Calendar Server. It is str
-
Hi, I'm new to Premiere Elements, having just bought Version 8. Can anyone please help me with a couple of issues? I would like to import Text as overlay over a slide & then animate it, instead of creating the text in the titler. I can easily p
-
2nd Monitor w/23" Cinema Display Issues
(I searched for this issue and came up empty.) The story is: I just acquired a 23" Cinema Display and am using it as my second monitor for my p-book 17" (1.67, OSX 10.39). It seems to want to mount the monitor completely arbitrarily. For instance, ju