Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

totalFrames of dynamically loaded swf

New Here ,
Nov 15, 2009 Nov 15, 2009

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.

TOPICS
ActionScript
8.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 07, 2014 May 07, 2014

i know this is old but i found it via google and thought i would correct the error.

you can reference avm1 swf properties (and methods) by using localconnection to communicate between the avm1 and avm2 swfs, SWF to SWF Communication when both swfs use actionscript 3.0

Translate
Participant ,
Nov 15, 2009 Nov 15, 2009

Try this:

trace(event.currentTarget.content.totalFrames);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2009 Nov 16, 2009

now I get this error:

ReferenceError: Error #1069: Property totalFrames not found on flash.display.AVM1Movie and there is no default value.
    at Untitled_fla::MainTimeline/xmlLoadedF()

THe movie I am loading has the animation embeded right in the main timeline.

What could be the problem now?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 16, 2009 Nov 16, 2009

Did this error occur after changing the trace? If so then try emmenting the error by commenting out the trace statement. The error shows it trying to get info from  Untitled_fla, is this the name of your fla file? Are you using AS2 or AS3?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2009 Nov 16, 2009

Hey,

The error occured after changing the trace.

The only code Ihave is the example code posted here as I want to make it work here and then focusonmy application.

Hence, the actual fla filename is untitled.fla

I am using AS3 and to movie I am trying to load is AS2

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 16, 2009 Nov 16, 2009

Because your script class was named CatProcess I saved the fla file as CatProcess and added the CatProcess in the fla Class Properties.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 16, 2009 Nov 16, 2009

Because your script class was named CatProcess I saved the fla file as CatProcess and added the CatProcess in the fla Class Properties.

Still can't send the fla? ummm

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2009 Nov 16, 2009

Does it work by renaming the files and adding the class?

Do you want me to send you the .fla?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2009 Nov 16, 2009

I'm not having much luck with this.

What I want to use this script for is for a player that loads both static images and flash movies dynamically from an xml.

It uses a timer to switch between picture after a couple for seconds. For movies however, it would have to wait for the movie to finish and then switch.

Is there any way to do this without using .totalFrames?

If not, the first question is still really valid.

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 16, 2009 Nov 16, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2009 Nov 16, 2009

It indeed is a display object.

However when I try to cast it as a movie clip using the line you mentioned inside the function it returns the following error.

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@f377701 to flash.display.MovieClip.
    at Untitled_fla::MainTimeline/xmlLoadedF()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 16, 2009 Nov 16, 2009

Turns out that you can't access the totalFrames (or _totalframes) of an AVM1Movie in AS3. There are no methods — so no stop() or gotoAndPlay(). And there are only a limited set of properties — x, y, alpha, but no totalFrames or currentFrame.

That is really annoying! I can kind of see why there are no methods, but having some properties, but not others is crazy.

Sorry I don't have better news for you there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2014 May 07, 2014
LATEST

i know this is old but i found it via google and thought i would correct the error.

you can reference avm1 swf properties (and methods) by using localconnection to communicate between the avm1 and avm2 swfs, SWF to SWF Communication when both swfs use actionscript 3.0

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines