Cannot load the SWFLoader content in a movieclip

339 views
Skip to first unread message

karan

unread,
May 16, 2007, 6:15:04 AM5/16/07
to flex_...@googlegroups.com
Hi guys,
    Im just trying to load a .swf in flex. Im using SWFLoader component for it. Once the .swf file gets loaded im assigning the content to a movieclip object. When i try to to that i get an error
    "TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@1cfa30f9 to flash.display.MovieClip."

    What i need is that, i want to load an .swf file and access it frame by frame.

Code i used:
   //SWFLoader complete event, imageHolder - is the id
   pdfHolder_mc = MovieClip(imageHolder.content);

   Can anyone of you help me out

--
regards
karan
mindrulers.blogspot.com

peacocksea

unread,
May 16, 2007, 9:32:56 AM5/16/07
to Flex India Community
Hi karan,

I guess the swf that you are trying to load using SWFLoader is
published using flash player 8 that is AVM1.

You can only load the AVM1 contents in mxml but can not access its
code or variables from the mxml application,
as it uses flash player 9 that is AVM2 to run the swf created using
mxml.

>From flex docs : "You can embed SWF files created for Flash Player 8
and earlier. When embedded, your Flex 2 application cannot interact
with the embedded SWF file. That is, you cannot use ActionScript in a
Flex 2 application to access the properties or methods of a SWF file
created for Flash Player 8 or earlier"

Hence you are getting error " Type Coercion failed: cannot convert
flash.display::AVM1Movie@1cfa30f9 to flash.display.MovieClip." as the
implementation of movieClip class in as2 is different from as3.

You can read the docs http://livedocs.adobe.com/flex/2/langref/migration.html

Regards
PS ε


http://livedocs.adobe.com/flex/2/langref/migration.html

karan

unread,
May 17, 2007, 12:47:38 AM5/17/07
to flex_...@googlegroups.com
So you mean to say that it is impossible to load a AVM1 SWF and access its properties in flex. Does adobe have any kind of solution to it.
   Ok. Have you come across any tool to convert the AVM1 SWF to AVM2 SWF.
   And one strange thing is that, i have a .swf file which was converted from .pdf (using the tool PDF2SWF), loads perfectly in flex and i can control its properties(totalFrames, gotoAndStop...).
   Is there any other way to accomplish my requirement ?
--
regards
karan
mindrulers.blogspot.com

mrinal wadhwa

unread,
May 17, 2007, 1:47:53 AM5/17/07
to flex_...@googlegroups.com

karan

unread,
May 17, 2007, 1:58:09 AM5/17/07
to flex_...@googlegroups.com
Mrinal,
    The problem is that i will not have any knowledge about the .swf i going to load. It will vary dynamically. So i can't use the LocalConnection class to communicate with each other.
   My requirement is i need to load a .swf and control its frames
--
regards
karan
mindrulers.blogspot.com

mrinal wadhwa

unread,
May 17, 2007, 2:04:20 AM5/17/07
to flex_...@googlegroups.com
Hmmm .. I'm clueless :? ... I don't think that can be done .. but I may be wrong.

karan

unread,
May 17, 2007, 2:26:29 AM5/17/07
to flex_...@googlegroups.com
:) Waiting for a miracle to happen
--
regards
karan
mindrulers.blogspot.com

Prayank Swaroop

unread,
May 17, 2007, 2:41:40 AM5/17/07
to flex_...@googlegroups.com
Maybe this will help a little?

I picked this one up from: http://www.senocular.com/pub/kirupa/as3tips_p7.html

senocular 09-25-2006 04:01 PM

AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
 
The ActionScript virtual machine that runs ActionScript 3 code (AVM2) is completely different from the ActionScript virtual machin that runs ActionScript 1 and ActionScript 2 code (AVM1). Because of this, you cannot call commands in an AVM1 movie from and AVM2 movie or vise versa. The virtual machines just are not compatible in that respect and mostly run in their own kind of shell that allows it to only interact with code being played back in that same virtual machine. What that boils down to is that ActionScript 3 cannot talk to AS1 or AS2 - at least not directly.

One thing these two virtual machines have in common is their implementation of LocalConnection. Both virtual machines deal with local connections in essentially the same way - enough that local connections in AVM1 can receive events from AVM2 and vise versa. So should you come into a situation where you would need a movie published in ActionScript 3 to communicate with a movie published in ActionScript 1 or 2, using local connection is the way to go.

Example:
ActionScript Code:
// ActionScript 2 file, AS2animation.fla
// one movie clip animation named animation_mc on the timeline

// local connection instance to receive events
var AVM_lc: LocalConnection = new LocalConnection( );

// stopAnimation event handler
AVM_lc.stopAnimation = function(){
    animation_mc.stop ();
}

// listen for events for "AVM2toAVM1"
AVM_lc.connect("AVM2toAVM1");

ActionScript Code:
// ActionScript 3 file, AS3Loader.fla

// local connection instance to communicate to AVM1 movie
var AVM_lc:LocalConnection = new LocalConnection();

// loader loads AVM1 movie
var loader:Loader = new Loader();
loader. load(new URLRequest("AS2animation.swf "));
addChild(loader);

// when AVM1 movie is clicked, call stopPlayback
loader.addEventListener(MouseEvent.CLICK , stopPlayback);

function stopPlayback(event:MouseEvent ):void {
    // send stopAnimation event to "AVM2toAVM1" connection
    AVM_lc.send("AVM2toAVM1", "stopAnimation" );
}


The AS3 movie loads the AS2 movie into a Loader instance and places it on the screen. As it plays, the user can click the animation which calls stopPlayback sending the "stopAnimation" event to the local connection named "AVM2toAVM1". The AS2 movie is then able to receive that event in its stopAnimation event handler and tell the animation_mc clip to stop.


Regards
Prayank

mrinal wadhwa

unread,
May 17, 2007, 2:46:36 AM5/17/07
to flex_...@googlegroups.com
Prayank,

I suggested the same thing  ... this is also called cross-scripting  ... but he cannot edit his AS2 swfs 

_
Mrinal

karan

unread,
May 17, 2007, 3:18:14 AM5/17/07
to flex_...@googlegroups.com
Yes Prayank. I will not be able to edit the swf's im trying to load. It will be loaded dynamically
--
regards
karan
mindrulers.blogspot.com

karan

unread,
May 17, 2007, 3:23:50 AM5/17/07
to flex_...@googlegroups.com
I heard that adobe is yet to support cross AVM communication. They are not supporting for security reasons. Is that so?
    What could be the security threat in this cas?
--
regards
karan
mindrulers.blogspot.com
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

learner

unread,
May 17, 2007, 1:01:17 AM5/17/07
to flex_...@googlegroups.com
There is a work around I see is through localVonnection.
Both AS2 and AS3 has same implementation of localConnection class
Please read the follwing technote. I hope it will help

http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16243

Regards
PS ε


On 5/17/07, karan <karan....@gmail.com> wrote:

learner

unread,
May 17, 2007, 1:04:41 AM5/17/07
to flex_...@googlegroups.com
Also the very good post on Kirupa by great person Senocular

http://www.kirupa.com/forum/showpost.php?p=1964550&postcount=249
It will definitely help.
Regards
PS ε
Reply all
Reply to author
Forward
0 new messages