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

load external swf by .extension and get totalFrames

Explorer ,
Jun 03, 2013 Jun 03, 2013

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

TOPICS
ActionScript
774
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

Guru , Jun 03, 2013 Jun 03, 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)

Translate
Guru ,
Jun 03, 2013 Jun 03, 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)

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
Explorer ,
Jun 03, 2013 Jun 03, 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

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
Guru ,
Jun 03, 2013 Jun 03, 2013
LATEST

sth.like

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

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