許可の問題(デバイスにデータを書き込むことはできません)のためクラッシュしています。
出力用にAIR/AS3またはコーディングツール(IDE)オプションを使用してそのようなアクセス許可を許可する方法を研究します。
も考慮してください。import flash.net.FileReference;
を追加
- を。
変数が関数の外で宣言されていることを確認してください。
それ以外の場合、var qfile:FileReference
は機能が起動されたときにのみ始まります。それはデスクトップ上のFlash Playerにとっては大丈夫ですが、モバイル上では、あなたのアプリケーションはAndroid OSと話をしなければなりません。そのOSは関数内に突然現れる宣言されていないファイルシステム編集変数を気に入らないかもしれません。デスクトップに「名前を付けて保存」ダイアログが表示され、モバイルデバイスではどのように動作しますか?おそらく、「保存」ボタンをクリックしたときに、AIRのFileSystem
APIを使用して:File
タイプをSDカードに自動的に保存する必要がありますか?
search resultsを確認して、他の人の操作方法に関するヒントを確認してください。
(更新されたコード):テストされていないが、最初の...
//## 1) add imports
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import com.adobe.images.JPGEncoder;
import flash.net.FileReference; //add this
//## 2) declare variables
var names:String = "Image_name";
var qImageData:BitmapData;
var qEncoder:JPGEncoder;
var qBytes:ByteArray;
//var qfile:FileReference = new FileReference();
var qFile:File = File.userDirectory.resolvePath(names+".jpg");
var qFStream:FileStream = new FileStream();
//## 3) add any required listeners
btn_save.addEventListener(MouseEvent.CLICK, save_image);
//## 4) declare all functions here onwards
function save_image(e:MouseEvent):void
{
btn_back.alpha = 0.4; //btn_back.visible = false;
btn_save.alpha = 0.4; //btn_save.visible = false;
qImageData = new BitmapData(540, 960);
qImageData.draw(stage);
qEncoder = new JPGEncoder(100);
qBytes = qEncoder.encode(qImageData);
//var qfile:FileReference = new FileReference();
//var names:String = "Image_name";
//qfile.save(qBytes, names+".jpg");
qBytes.position = 0;
qFStream.open(qFile, FileMode.WRITE);
qFStream.writeBytes(qBytes, 0, qBytes.length);
qFStream.close();
btn_back.alpha = 0.4; //btn_back.visible = true;
btn_save.alpha = 0.4; //btn_save.visible = true;
//## Check if file (qFile) was created successfully (it exists on SD card)
if (qFile.exists)
{
//# Do something if "The File Exists" on the SD card...
}
else
{
//# Here will handle case of "No File Created"...
}
}
(その後、研究の権限の問題を動作しない場合は、代わりFileReference
のFile
を試してみてください)、以下のようなコードを設定してみてくださいまた、Android manifest allowsWRITE
の権限を持っていることを確認してください。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
それはapp.xml
またはYourFileName-app.xml
という名前のファイルになります。
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<application xmlns="http://ns.adobe.com/air/application/2.5">
<id>author.YourFileName</id>
<versionNumber>1.0.0</versionNumber>
<versionLabel/>
<filename>YourFileName</filename>
<description/>
<!-- To localize the description, use the following format for the description element.<description><text xml:lang="en">English App description goes here</text><text xml:lang="fr">French App description goes here</text><text xml:lang="ja">Japanese App description goes here</text></description>-->
<name>YourFileName</name>
<!-- To localize the name, use the following format for the name element.<name><text xml:lang="en">English App name goes here</text><text xml:lang="fr">French App name goes here</text><text xml:lang="ja">Japanese App name goes here</text></name>-->
<copyright/>
<initialWindow>
<content>YourFileName.swf</content>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<fullScreen>true</fullScreen>
<renderMode>gpu</renderMode>
<autoOrients>true</autoOrients>
</initialWindow>
<icon>
<image72x72>My_Assets/icons/YourFileName_icon_72.png</image72x72>
<image48x48>My_Assets/icons/YourFileName_icon_48.png</image48x48>
<image36x36>My_Assets/icons/YourFileName_icon_36.png</image36x36>
</icon>
<customUpdateUI>false</customUpdateUI>
<allowBrowserInvocation>false</allowBrowserInvocation>
<android>
<manifestAdditions>
<![CDATA[<manifest>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>]]>
</manifestAdditions>
</android>
</application>
引用::* save()メソッドは、最初のファイル名を入力して、ファイルを保存するには、ローカルコンピュータ上の場所を選択するようにユーザーに要求するオペレーティングシステムのダイアログボックスを開き、それはこのようなものだことを確認してください。 *私はAndroidがダイアログボックスのようなものを持っているとは思わない。代わりに、** File **と** FileStream **クラスを使用する必要があります。 – Organis
ご回答いただきありがとうございます。上記コードのどの部分を修正する必要がありますか? –
https://stackoverflow.com/questions/7858670/save-image-in-a-directory-in-applicationstoragedirectory – Organis