Skip to main content
Inspiring
June 3, 2013
Answered

load external swf by .extension and get totalFrames

  • June 3, 2013
  • 1 reply
  • 842 views

What I am trying to achieve is dragging and droping a swf into this app while trace its totalframes.

But no luck yet, cant seem to ge the file.extension to be loaded.

code so far:

package

{

          import flash.display.Sprite;

          import flash.text.TextField;

          import flash.filesystem.File;

          import flash.events.Event;

          import flash.events.NativeDragEvent;

          import flash.display.MovieClip;

          import flash.desktop.NativeDragManager;

          import flash.desktop.Clipboard;

          import flash.desktop.ClipboardFormats;

          import flash.net.URLRequest;

          import flash.display.Loader;

          import flash.events.Event;

          import flash.events.ProgressEvent;

          import flash.events.IOErrorEvent;

          public class Main extends Sprite

          {

                    private var dragTarget:Sprite = new Sprite();

                    private static var myLoader;

                    var currentfile;

                    public function Main()

                    {

                              addEventListener(Event.ADDED_TO_STAGE, doStage);

                    }

                    private function doStage(e:Event):void

                    {

                              tv_mc.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, doDragEnter);

                              tv_mc.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, doDragDrop);

                              //tv_mc.addEventListener(NativeDragEvent.NATIVE_DRAG_EXIT, doDragExit);

                    }

                    private function doDragEnter(e:NativeDragEvent):void

                    {

                              NativeDragManager.acceptDragDrop(tv_mc);

                    }

                    private function doDragDrop(e:NativeDragEvent):void

                    {

                              var dropFiles:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;

                              for each (var file:File in dropFiles)

                              {

                                        switch (file.extension)

                                        {

                                                  case "swf" :

                                                            path_txt.text = file.nativePath;

                                                            currentfile = file.extension;

                                                            //swfLoader.addEventListener(Event.INIT, loader_init);

                                                            loadswf();

                                                            break;

                                                  default :

                                                            path_txt.text = "Not a recognised file format";

                                        }

                              }

                    }

                    private function loadswf():void

                    {

               trace(currentfile)

                              var mLoader:Loader = new Loader();

                              var mRequest:URLRequest = new URLRequest(currentfile);

                              mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);

                              mLoader.load(mRequest);

                    }

                    private function onCompleteHandler(loadEvent:Event)

                    {

                              trace("loaded")

                    }

          }

}

any help is welcome!

Thx pavel

This topic has been closed for replies.
Correct answer moccamaximum

part of the problem is that current file  gives only the fileextension

currentfile = file.extension;

and urlrequest  expects the whhole path

var mRequest:URLRequest = new URLRequest(currentfile);

also: if you are dragging multiple files on your app you will also run into trouble, instead osf starting the loading immedaiately you have to build sth like a loader queue (or throwing an exception if multiple files are dropped into your app)

1 reply

moccamaximumCorrect answer
Inspiring
June 3, 2013

part of the problem is that current file  gives only the fileextension

currentfile = file.extension;

and urlrequest  expects the whhole path

var mRequest:URLRequest = new URLRequest(currentfile);

also: if you are dragging multiple files on your app you will also run into trouble, instead osf starting the loading immedaiately you have to build sth like a loader queue (or throwing an exception if multiple files are dropped into your app)

pa-pavelAuthor
Inspiring
June 3, 2013

Thx thought this might me the case. Ill add the que part later on.

So what would I refer to as currentfile?

file.name + extenssion ?


Cheers, Pavel

Inspiring
June 3, 2013

sth.like

currentfile = file.nativePath+"/"+file.name+"."+file.extension