Accessing a class from a loaded SWF
In Flash Professional, I drew a shape, converted it to symbol, linked it to class Symbol1 (extends MovieClip) which is generated at run-time, and saved the SWF file as shape.swf.
Now my main application wants to load shape.swf and create multiple instances of Symbol1 but I get ReferenceError when trying to access the class Symbol1.
Below is my main application's code. Errors thrown are mentioned in comments.
public class MovieClipTest extends Sprite
public function MovieClipTest()
var url:String = 'shapes.swf';
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, f);
l.load(new URLRequest(url), new LoaderContext(false, ApplicationDomain.currentDomain));
private function f(event:Event):void
var content:Sprite = (event.currentTarget as LoaderInfo).content as Sprite;
trace(getQualifiedClassName(content.getChildAt(0))); // output: Symbol1
trace(ApplicationDomain.currentDomain.getDefinition('Symbol1')); // throws Error #1065: Variable Symbol1 is not defined.
trace(getDefinitionByName('Symbol1')); // throws Error #1065: Variable Symbol1 is not defined.
Your "Symbol" is obviously not in the current ApplicationDomain, but in the loaded SWF's domain:
var symbolClass:Class = event.target.applicationDomain.getDefinition("Symbol") as Class;
var symbolInstance:MovieClip = new symbolClass() as MovieClip;
Also because you're loading a SWF, the content of the Loader is a MovieClip, not a Sprite.
Kenneth Kawamoto
http://www.materiaprima.co.uk/
Similar Messages
-
Loading class from an external .swf file
Hi,
My flash application has lots of resources which will change all the time. In order to keep the the user from having to download my main .swf file over and over again, and in order to keep the main file's size low, I would like to put the resources into separate .swf files and load them dynamically from a url using a Loader.
Once downloaded I would like to extract the classes that are in the resource swf and use them in the main swf. Can anyone share some code for doing this? Note that I am not just interested in using a symbol from the resource swf. I would like to use a class, with all of its methods and everything, and my main swf does not contain the class definition. Only the resource swf does.
Thanks!!This is a great question for flash programming.
And when you know the answer to this, you are likely to use it on daily basis like the top level programmers of an agency.
ApplicationDomain is your answer and the adobe docs has a chapter on this.
ApplicationDomain is where all of your classes will be loaded into and when you use a loader you have the ability to target this with the laoderContext.
AplicationDomain.currentDomain loads all classes into the main app and if your main app already has these classes, then the app uses the parents classes
new Application.Domain() specifies a seperate repo of classes that are loaded in so that classes in the main app will not be confused by the classes in a loaded swf. that refer to the same names.
this locks down the communication between the swfs but will use the newer updated classes on the child when a child is loaded in with the same class names as the parents.
new ApplicationDomain(currentDomain) will enclose a new repo with the parent repo of the class definitions. -
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. -
Controlling a Movie Clip on the Main Timeline from a loaded SWF?
Is it possible to control a MovieClip on the main timelne from another loaded clip?
I see posts that control loaded clips, but most are all from the loader in the main timeline. I have a moviclip on the main timeline that I want to make visible or invisible depending on what keyframe is playing in another loaded swf.
If I try to call the movieClip from the loaded SWF I get "error #1119. Access of possibly undefined property...." because it doesn't exist in the loaded SWF, just the main timeline.
The old AS2 way just used "_root". Since "_root" doesn't exist any more, how do you control items on the main TimeLine from a loaded SWF?I am not clear what you mean because you are saying you are trying to target a movieclip that does not exist where you are trying to target it.
Try using a trace to see what you are targeting when you you target the MovieClip(parent.parent)....
trace(MovieClip(parent.parent));
The other approach I mentioned earlier is the more OOP-correct approach if you would rather try that way. Here's a rough outline of it...
AS3 - Dispatch Event
http://forums.adobe.com/thread/470135?tstart=120
Example:
Add something to trigger the event in the child (your loaded swf):
dispatchEvent(new Event("eventTriggered")); (
if dispatchEvent problem, see: http://www.kirupa.com/forum/showthread.php?p=1899603#post1899603)
In your loading/parent swf, listen for the complete event on the Loader.contentLoaderInfo. In the complete event handler, add a listener for the event on the loaded swf.
// event handler triggered when external swf is loaded
function loaderCompleteHandler(event:Event) {
MovieClip(event.currentTarget.content).addEventListener("eventTriggered", eventHandler);
function eventHandler(event:Event):void {
trace("event dispatched in loaded swf");
// this is where your main file can set the visible property of your movieclip -
Calling a function in the main movie from a loaded swf
I realize this is probably a very basic question, but I have
loaded a SWF file into another movie. I now want to call a function
in the main SWF. Is there a way to do that? Alternatively, I have a
custom class where I could put the function, but I haven't been
able to figure out how to call it from the loaded SWF either. Do I
somehow need to associate the class with the main movie,
or...?Never mind - I was doing something very stupid and wasn't
calling the function as a method of a movie clip. I was simply
calling checkTarget(event) rather than
event.currentTarget.checkTarget(event); which seems to work. -
Calling a function in a flex app from a loaded SWF
How can I call a function in a flex application from a loaded
swf file?Two ways:
Application.application returns a reference to the top-level
application scope. You can access any public member, var, function,
component, etc through that reference.
Dispatch an event event form the loaded swf and use a event
handler in the main app. All the gurus advise this as best
practice, to ensure "loose coupling" It is also pretty easy,
especially if you use a bubbling event.
Tracy -
Listening to Events from inside loaded swf
In Flash Builder 4 I have a swfLoader with which I load swf files. The swf files that get loaded get created in Flash Pro, and I would like to be able to listen for events from the level that they get loaded from. What would I have to specify in the Flash file for the path? Can't seem to be able to specify the right path.
Thanks a lot for any help!I wouldnt say this is elegant but we have been having issues gaining direct access to the SWF's loaded in via OSMF. However I have done setups where I dispatch an event from a SWF and have it bubble up and catch it on the MediaContainer level. Not elegant but works- otherwise may need to make a custom MediaElement and bypass the SWFElement to gain tighter control - seems like there should be a better way, but I havnt found it.
-
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"); -
Class not Found when accessing Proxy class from backing bean in VC.
Hi All,
I'm attempting to access a class of a webservice(generated as a proxy) within my ADF application and invoke the method within a backing bean of the View Controller(bean scope : backing bean). The proxy has generated an ObjectFactory class among other classes. When I access this Object factory class from within the backing bean, the application throws a Class not found error.
I don't know where the error lies since I've declared the View Controller of the ADF application dependent on the Proxy and I've imported the class and accessing it within a backing bean. How would you suggest I approach resolveing this.
JDev : 1.1.1.4
Thank you.
Regards
PP.Hello Arun,
Thank you for suggesting a Data control, but my requirement isn't to drag and drop the method as a button. It's more of a behind the scnes updating data via a database adapter requirement.
I've resolved the issue. turns out, my deployment archive didn't include the proxy.jpr. Once included it works likea charm.
Thanks
PP. -
Accessing custom classes from JSP
Hi Guys,
I am having some problems accessing my custom classes from my JSP.
1) I've created a very simple class, SimpleCountingBean that just has accessors for an int. The class is in the package "SimpleCountingBean". I compiled this class locally on my laptop and uploaded the *.class file to my ISP.
2) I've checked my classpath and yes, the file "SimpleCountingBean/SimpleCountingBean.class" is located off of one of the directories listed in the classpath.
3) When I attempt to use this class in my JSP, via the following import statement:
import "SimpleCountingBean.*"
I get the following compile error
java.lang.NoClassDefFoundError: SimpleCountingBean/SimpleCountingBean
I'm pretty sure that my classpath is properly setup because when I purposely garble the import statement, I get the "package not found" compile error.
Do I need to upload some other files in addition to the class file? Any suggestions would of course be appreciated.
Sonny.Trying to get some clearer view.. so don't mind..
So you uploaded all your .jsp files into your account which is:
home/sonny
and it compiles and work. But custom classes doesn't seems to be working, where did you place your classes?
From my knowledge of tomcat, classes are normally placed in, in this case:
home/sonny/web-inf/classes
Maybe it differs from windows enviroment to *nix enviroment.. well, I'm just saying out so if its not the case.. don't mind me. -
EJBs accessing protected classes from java classloader
Hello,
We are facing a problem with classes isolation. I read from this newsgroup that
to access a package level class from the base classloader from a bean, the supporting
classes has to be from the same classloader as the bean. Well I think the only
way we could do that is to have the *Bean.class in the base classloader, which
is not what's recommended or move the support classes into the bean's classloader,
which we cannot do.
The purpose of this mail is to ask: is it a bug from weblogic server? Will it
be fixed one day? If not, does it mean that it is impossible to isolate classes
for local access from public classes?
Thank you, Khiet.Thank you for your reply.
Hope that one day we will not be obliged to have anything in the main classpath.
:) Khiet.
Rob Woollen <[email protected]> wrote:
Tran T. Khiet wrote:
Hello,
We are facing a problem with classes isolation. I read from this newsgroupthat
to access a package level class from the base classloader from a bean,the supporting
classes has to be from the same classloader as the bean. Well I thinkthe only
way we could do that is to have the *Bean.class in the base classloader,which
is not what's recommended or move the support classes into the bean'sclassloader,
which we cannot do.All correct.
The purpose of this mail is to ask: is it a bug from weblogic server?No, it's how java classloaders work.
Will it
be fixed one day? If not, does it mean that it is impossible to isolateclasses
for local access from public classes?You can expect that future versions of WLS will allow the user more
control over classloaders, but for now you'll need public or protected
access to cross classloaders.
-- Rob
Thank you, Khiet. -
Accessing Java Classes from Forms
Is is possible to access a Java class from Forms? I have been
creating an Active X control that returns a Java object, and from
that I can call methods on that object, but I would really like
to do that without having and Active X control in the mix. Any
suggestions?
nullOracle Developer Team wrote:
: Robert Nocera (guest) wrote:
: : Oracle Developer Team wrote:
: : : hey robert -
: : : Developer 6.0 provides this ability for web deployment.
You
: : can
: : : insert your own custom Java components into your
application
: : and
: : : they will appear in the application when it is run via the
: web.
: : : If you look at the documentation for 6.0, there are a few
: : : section son Pluggable Java Components and JavaBeans that
: : : describes what is provided and how you use the interfaces
: and
: : : classes we provide.
: : : A whitepaper on this topic will be posted to the OTN
: shortly,
: : as
: : : well as some samples that illustrate how to go about doing
: it.
: : : cheers!
: : : -Oracle Developer Team-
: : Thanks for the quick response. Is there any way to access
: those
: : classes without being in a web deployment. That's probably
: not
: : totally out of the question, but what we had in mind was
: adding
: : some Java Functionality (actually connectictivity to some
EJBs
: : that we have) to existing forms. Currently there forms are
: not
: : deployed in a "web" environment and are just run from the
: forms
: : runtime engine.
: : -Rob
: hey again robert -
: there's no easy way (yet!) to call out from forms runtime
: process to a Java application.
: We've played around some with creating an ORA_FFI interface to
: JNI and then wrappering this with PL/SQL code. We've been able
: to make calling into an EJB running in 8i from a forms runtime
: work using this approach.
: Let me know if this is of interest to you and I can post the
: stuff we've currently got. It's no more than a simple demo and
: is not complete. It requires quite a bit of manual coding on
: the PL/SQL side since the interface emulates JNI (FindClass,
: GetMethodID, CallMethodID, etc.).
: cheers!
: -the Oracle Developer Team-
I'd be interested in this ORA_FFI doc you've been playing with.
Would you please email it to me or post it.
null -
Accessing IFS classes from Weblogic
Can I access the classes of IFS from within Weblogic by adding the IFS jars to the Classpath of Weblogic?
Also how does EJBs work with IFS?
Kaustuva MukherjeeI'm doing exactly the same thing that you are asking. first install ifs client on weblogic server, so that all ifs jar files are on weblogic. then do this in the weblogic class path file:
REM ------------------ IFS CLASSPATH ------------------------
SET IFS_CLASSPATH=d:\Oracle\Ora81\ifs1.1\lib\adk.jar;d:\Oracle\Ora81\ifs1.1\lib\clientlib.jar;d:\Oracle\Ora81\ifs1.1\lib\cmdlineutils.jar;d:\Oracle\Ora81\ifs1.1\lib\cup.jar;d:\Oracle\O ra81\ifs1.1\lib\http.jar;d:\Oracle\Ora81\ifs1.1\lib\oemadmin.jar;d:\Oracle\Ora81\ifs1.1\lib\release.jar;d:\Oracle\Ora81\ifs1.1\lib\repos.jar;d:\Oracle\Ora81\ifs1.1\lib\utils.jar;d: \Oracle\Ora81\ifs1.1\lib\webui.jar;d:\Oracle\Ora81\ifs1.1\settings
and include IFS_CLASSPATH in your weblogic path.
restart weblogic and u'll have all ifs classes for your use.
null -
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? -
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."
Maybe you are looking for
-
Verizon doesn't care if you pay for Priority Overnight.
I preordered the Note 3, and picked priority overnight shipping, it cost me $14.99. First of all, when I preordered my S4 I got overnight as well, I ended up receiving the phone earlier than most customers, and I got it before I go into work. That be
-
Hi All, I'm trying to daisy-chain 2 Motu 8pre's using ADAT into LE9. Logic happily recognises one 8pre when used alone. But when I chain the 2 together the only way I can get input is if I use Motu's 'CueMix FX' software. My proplem with that is....b
-
Why is the Amber update different for ATT and Chin...
Why is the Amber update different for ATT and China? For Lumia 520, it could tap to unlock but, in china, this function is disappeared disappear. Could you give an expain as the matching hardware, otherwise I think it's a definately discriminatory to
-
I have seen several threads about this issue, but so far I can't figure it out. I don't know if my problem is different from the other people or if I am just missing something in the other threads. I can login as SYSDBA if I set the ORACLE_SID variab
-
Business Partner - Number Ranges and Groupings
Hello, A few weeks ago, we are activated RMCA components and activated Telecommunications 6.0 in a sand box client. Now we are doing customizing and application of BP. We want, and we could, to range BP in number range from 1 to 9999999999, as the co