-1

I use Adobe Flash Professional CS6 + as3 and I have a button to download or save as the video in the desktop but does not execute it? Why ? Where is the mistake?

import fl.video.FLVPlayback;
import flash.display.StageAlign;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import flash.media.SoundMixer;



myVideoPlayer.source = "";
addChild (myVideoPlayer);

function loadMyVideo (url:String):void
{
    myVideoPlayer.source = url;
    myVideoPlayer.visible = true;
}


videosaveas.addEventListener (MouseEvent.CLICK, videosaveas2);
function videosaveas2 (e:Event):void
{

    file = new FileReference();
    var fileReference:FileReference=new FileReference();
    file.save (ByteData, "video.mp4");
}
akmozo
  • 9,829
  • 3
  • 28
  • 44
FlashGirl
  • 53
  • 11
  • There are many examples just do some research using your favorite SE ; [1](http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cf8.html#WSD7D78288-ADD8-422d-AF79-AE803643F71F), [2](http://stackoverflow.com/a/2974055/2256820), [3](http://code.tutsplus.com/tutorials/quick-tip-download-files-via-swfs-using-filereference--active-9068), ... – akmozo Aug 02 '16 at 10:11
  • Is this an AIR app or a Flash Player one ? And how did you think you will publish it ? – akmozo Aug 04 '16 at 10:03
  • @akmozo I want the two together .. very urgent. " AIR and AS3 Where the problem in why does not perform it's Thank you very much – FlashGirl Aug 08 '16 at 05:23

1 Answers1

1

I don't know if you know the difference between a Flash Player app and an AIR one but I'll put an example for an offline Flash Player app to download a file which is in the same directory as the SWF.

To load the file, I'll use an URLLoader object and then save it using a FileReference one.

Here, don't forget that FileReference.save() is allowed only after a user action (like a mouse click or keypress).

For the example, I'll use the same button for both operations (the user should press the button twice to get the saving file dialog).

var url_loader:URLLoader;

// at the first, we use the button to load the file
btn_download.addEventListener(MouseEvent.CLICK, load_the_file);

function load_the_file(e:MouseEvent): void {
    url_loader = new URLLoader();
    url_loader.dataFormat = URLLoaderDataFormat.BINARY;
    url_loader.addEventListener(Event.COMPLETE, function(e:Event){
        btn_download.removeEventListener(MouseEvent.CLICK, load_the_file);
        // then we use the same button to download the file
        btn_download.addEventListener(MouseEvent.CLICK, download_the_file);
    })
    url_loader.load(new URLRequest('file_path.ext'));
}

function download_the_file(e:MouseEvent): void {
    var file_reference:FileReference = new FileReference()
        file_reference.save(url_loader.data, 'default_file_name.ext');
    btn_download.removeEventListener(MouseEvent.CLICK, download_the_file);
}

Here, using one button is just an example so you can, for example, show a loading message, use another way to load the file, use two buttons, ...

Then for an online app (a web app), you can use, for example, FileReference.download() :

var file_ref:FileReference = new FileReference();
    file_ref.download(new URLRequest('http://www.example.com/file_path.ext')); 

For AIR, you have a lot of possibilities using the File, FileStream and the FileReference classes, and you have a lot of example on the net ...

Hope that can help.

akmozo
  • 9,829
  • 3
  • 28
  • 44
  • First, thank you for helping me .. Video was shown at work from a folder \ Videos .. I just want to save it again in, for example, the desktop .. – FlashGirl Aug 09 '16 at 08:03
  • @FlashGirl I don't understand your problem, that code is saving a file in any directory selected by the user, did you tried it ? – akmozo Aug 09 '16 at 09:12
  • Yes I tried it But it shows me a window to save And I want to save the video appears in front of me ??? – FlashGirl Aug 09 '16 at 09:26
  • Do you want to save the file without any interaction with the user ? – akmozo Aug 09 '16 at 09:38
  • Yes, by clicking on the button saves the video to the desktop, for example, – FlashGirl Aug 09 '16 at 09:41
  • In that case, you should use AIR. For an example, take a look [here](http://stackoverflow.com/a/31057995/2256820) (the AIR part), you have juste to use `File.desktopDirectory` ... – akmozo Aug 09 '16 at 09:48
  • Can you try it in the file I sent to you? – FlashGirl Aug 09 '16 at 09:55
  • See the video does not show the name and extension [link](https://drive.google.com/file/d/0B9BcYjTM8tPoM0hFYWFMaXZnSWc/view?usp=sharing) – FlashGirl Aug 10 '16 at 06:30
  • The "default_file_name.ext" value is just to indicate that you can set a default name of the saved file, you should change it (if you want to put a default name), to something like "video.mp4" or the same name as the current video, or anything else ... – akmozo Aug 10 '16 at 09:46
  • >>>>>>> I wrote that in the xml file .........and in my as3 file I wrote `btn_download.addEventListener (MouseEvent.CLICK, saveMyVideo); function saveMyVideo (url:String):void { //myVideoPlayer.source = url; file = new FileReference(); var file:FileReference = new FileReference(); file.save ("video.mp4"); }` .......The problem is not executed Save Video????? – FlashGirl Aug 14 '16 at 09:00
  • @FlashGirl Could you explain what's the problem exactly ? – akmozo Aug 15 '16 at 11:04
  • `btn_download.addEventListener (MouseEvent.CLICK, saveMyVideo); function saveMyVideo (url:String):void {var videoTypeFilter:FileFilter = new FileFilter("Video files","*.3gp; *.asf; *.asx; *.avi; *.flv; "); var file:FileReference = new FileReference(); file.addEventListener (Event.SELECT, videoTypeFilter); myVideoPlayer.source = url; file = new FileReference(); var file:File = File.desktopDirectory; file.addEventListener (Event.SELECT, loadMyVideo); myVideoPlayer.source = "theme.xml"; file.save (myVideoPlayer,"video.mp4"); }` – FlashGirl Sep 01 '16 at 09:12