Error 1119 when creating "Load Text" button - actionscript-3

A section of a Flash animation I'm creating involves an area where people can write on a notepad, save their work and update it at a later time. The file will be downloaded by users before they run it, rather than from a webpage. Here is the code I have so far:
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.display.MovieClip;
import flash.events.Event;
stop();
var MyNotes:FileReference = new FileReference()
Save_btn.addEventListener (MouseEvent.CLICK, SaveText);
function SaveText(Event:MouseEvent):void {
MyNotes.save(TypeOwn_txt.text, "MyNotes.txt");
}
Load_btn.addEventListener (MouseEvent.CLICK, LoadText);
function LoadText(Event:MouseEvent):void {
MyNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; .html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
MyNotes.browse([swfTypeFilter, allTypeFilter]);
}
function onFileSelected(event:Event):void
{
trace("onFileSelected");
MyNotes.addEventListener(Event.COMPLETE, onFileLoaded);
MyNotes.load();
}
function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
TypeOwn_txt.text=data.toString();
}
The problem is I receive a "Symbol 'Structure Summary', Layer 'Actions', Frame 29, Line 19 1119: Access of possibly undefined property SELECT through a reference with static type flash.events:MouseEvent.
" in regards to the line "MyNotes.addEventListener(Event.SELECT, onFileSelected);". I've done some research and understand this is something to do with the parent not being identified as a MovieClip, or something along those lines. I'm still not sure, however I don't have a clue how to proceed! Thanks.

Just to let you know the problem is solved, although I really don't know how. I used this site for a template and worked backwards. I'll put in the working Code below in case it's of use to somebody else.
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.display.MovieClip;
var myNotes:FileReference;
Load_btn.addEventListener(MouseEvent.CLICK, onLoadClicked);
function onLoadClicked(event:MouseEvent):void
{
trace("onBrowse");
myNotes=new FileReference();
myNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; *.html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
myNotes.browse([swfTypeFilter, allTypeFilter]);
}
function onFileSelected(event:Event):void
{
trace("onFileSelected");
myNotes.addEventListener(Event.COMPLETE, onFileLoaded);
myNotes.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
myNotes.load();
}
function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
textArea.text=data.toString();
myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
}
function onFileLoadError(event:Event):void
{
myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
trace("File load error");
}
Save_btn.addEventListener (MouseEvent.CLICK, SaveText);
function SaveText(Event:MouseEvent):void {
myNotes=new FileReference();
myNotes.save(textArea.text, "MyNotes.txt");
}
Thanks to everyone who contributed.

Related

How to set JPG type of image screenshot saved from flash using Actionscript 3?

I have a problem when i wanna save screenshot entire flash stage using ActionScript 3. when i click button that use function SimpanGbr it's works for saving image with name "NamaGambar" but without type of JPG image. How to save image with it's type. I use these codes:
stop();
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import com.adobe.images.JPGEncoder;
stage.displayState = StageDisplayState.FULL_SCREEN;
exit.addEventListener(MouseEvent.CLICK,keluar);
function keluar(event:MouseEvent):void
{
fscommand("quit");
}
function SimpanGbr(e:MouseEvent):void {
var qImageData:BitmapData = new BitmapData(800, 600);
qImageData.draw(stage);
var qEncoder:JPGEncoder = new JPGEncoder(100);
var qBytes:ByteArray = qEncoder.encode(qImageData);
var qFile:FileReference = new FileReference();
var nama:String="NamaGambar";
qFile.save(qBytes, nama+".jpg");
}
You can do so using this library.
After downloading copy the source files (the com folder) on to your Class path or your application root directory. Apart from the JPEGEncoder, this library is packaged with a lot of other classes related to Hasing, Text, Date etc.
This is how we save an image from a flash movie to a local machine.
1) Create a BitmapData object out of the MovieClip or the Loader.
2) Encode the BitmapData using the JPEGEncoder and form a ByteArray.
3) Use FileReference.save() to download the image on to the User machine.
See an example:
Create a blank Flash movie and name it as “ImageSave.fla”. In the same folder create “ImageSave.as” file and copy the below code in to it. You need the “com” folder copied from the as3corelib to this folder. I have a button on the stage named “save_mc” which triggers the saveImage function.
package {
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.utils.ByteArray;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import com.adobe.images.JPGEncoder;
public class ImageSave extends MovieClip {
private var imgFile:URLRequest;
private var img:MovieClip;
private var imgLoader:Loader;
private var file:FileReference;
public function ImageSave() {
imgFile = new URLRequest("coffee.jpg"); //change it to your image path
imgLoader = new Loader();
imgLoader.load(imgFile);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
save_mc.addEventListener(MouseEvent.CLICK, saveImage);
}
private function onLoaded(evt:Event):void {
imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaded);
imgLoader.cacheAsBitmap = true;
addChild(imgLoader);
}
function saveImage(e:MouseEvent):void {
var myBitmapData:BitmapData = new BitmapData(imgLoader.width, imgLoader.height);
myBitmapData.draw(imgLoader);
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);
file = new FileReference();
file.browse(new Array(new FileFilter("Images (*.jpg, *.jpeg)", "*.jpg;*.jpeg")));
file.save(imgByteData, "test.jpg");
}
}
}
For your convenience you can download a working copy of this sample here.

Incorrect calling of external mp3 file

I am getting Error:#2044, so I assumed that my code is wrong in calling the Sound functions but I can't seem to find where I am making the error.
package {
import flash.display.MovieClip;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.net.URLRequest;
public class Tile extends MovieClip{
public function GetAndSwitchKey():String {
//Some Code//
//Create sounds
//------------> Start here
var bSound:Sound = new Sound();
var bReq:URLRequest = new URLRequest("B.mp3");
var oSound:Sound = new Sound();
var oReq:URLRequest = new URLRequest("O.mp3");
var mSound:Sound = new Sound();
var mReq:URLRequest = new URLRequest("M.mp3");
//Load sounds
bSound.load(bReq);
oSound.load(oReq);
mSound.load(mReq);
//<-------- End here
//Some code//
switch (temp) {
case "B": bSound.play(); break;
case "O": oSound.play(); break;
case "M": mSound.play(); break;
}
//Some code//
}
}
}
The way I added the files is by placing them inside the same file as the Action script 3 file. I also then changed them in the propperties to be exportable for action script. But as far as I am aware I don't have to specify the directory since a copy is made in the SWF.
Replacing the code indicated between the "start here" and "end here". This will resolve the error. And will call the sound file properly.
var mySoundHolder = new mySound();

Problems with STAGE

I am pretty new to as3 programming. This forum helped me already a lot, but now I have a problem where I don't know how to get on. So this is my first Post on stack overflow.com.
I need StageWebView for displaying a PDF-document. After several hours, I was successful. I created the code in a new blank document and tested it step by step.
This is my code:
import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.filesystem.File;
import flash.display.Sprite;
import flash.display.Stage;
public function StageWebViewExample(pdfdoc:String, xpos:Number, ypos:Number, breite:Number, hoehe:Number)
{
var webView:StageWebView = new StageWebView();
webView.stage = this.stage; //PROBLEM LINE
webView.viewPort = new Rectangle (xpos, ypos, breite, hoehe);
var file:String = pdfdoc;
var pdf:File = File.applicationDirectory.resolvePath(file);
webView.loadURL(pdf.nativePath);
}
StageWebViewExample("test.pdf", 200, 200, 600, 1200);
After testing, I copied the code in my existing flash-document. (The code in a several as-File and the "calling" (StageWebViewExample("....) in the existing flash-document...)
But now the code does't work anymore and there are the following Errors:
- 1119 Access of possibly undefined property stage...
- 1059 Property is read-only.
--> Both Errors referring to the same line I marked in the Code.
Has anyone an idea why it don't work?
I would really appreciate a good hint!
Answer for question is your actions ;) You moved code from the Document Class, in another one, that don't have access to the stage as instance property. I mean this.stage.
Pass Stage also to the method StageWebViewExample, function signature will look like:
public function stageWebViewExample(stage: Stage, pdfdoc:String, xpos:Number, ypos:Number, breite:Number, hoehe:Number):void {
var webView:StageWebView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectangle (xpos, ypos, breite, hoehe);
var file:String = pdfdoc;
var pdf:File = File.applicationDirectory.resolvePath(file);
webView.loadURL(pdf.nativePath);
}
Working AIR example:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.media.StageWebView;
public class StackOverflow extends Sprite {
public function StackOverflow() {
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function onAdded(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
start();
}
private function start():void {
showWebViewAt(this.stage, "http://www.iab.net/media/file/VASTv3.0.pdf", new Rectangle(0, 0, stage.stageWidth * 0.5, stage.stageHeight));
}
private function showWebViewAt(stage:Stage, path:String, frame:Rectangle):void {
var webView:StageWebView = new StageWebView();
webView.stage = stage;
webView.viewPort = frame;
webView.loadURL(path);
}
}
}

Error #1010 at falsh as3

i am new to flash, i was created volume slider, and i was clearly created instance for all volume function but it give the follow error
TypeError: Error #1010: A term is undefined and has no properties.
the exact error place in the following code is
bgslider.mc.addEventListener(MouseEvent.MOUSE_DOWN,StartDrag);
my player code is
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.events.Event;
import flash.geom.Rectangle;
btnstop.addEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.addEventListener(MouseEvent.MOUSE_OVER,StopOver);
function StopOver(evt:MouseEvent):void
{
btnstopo.visible=false;
btnstop.visible=true;
}
function StopOut(evt:MouseEvent):void
{
btnstop.visible=false;
btnstopo.visible=true;
}
btnplay.addEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.addEventListener(MouseEvent.MOUSE_OVER,PlayOver);
function PlayOver(evt:MouseEvent):void
{
btnplayo.visible=false;
btnplay.visible=true;
}
function PlayOut(evt:MouseEvent):void
{
btnplay.visible=false;
btnplayo.visible=true;
}
var soundfile:URLRequest = new URLRequest('http://live32.radio.com:80/;stream1.mp3');
var channel:SoundChannel = new SoundChannel();
var sTransform:SoundTransform = new SoundTransform();
var isplay=1;
var myMusic:Sound = new Sound();
myMusic.load(soundfile);
channel=myMusic.play();
btnplay.addEventListener(MouseEvent.CLICK,PlayRadio);
btnstop.addEventListener(MouseEvent.CLICK,StopRadio);
function PlayRadio(evt:Event):void
{
if(isplay==0)
{
isplay=1;
btnplay.removeEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.removeEventListener(MouseEvent.MOUSE_OVER,PlayOver);
btnstop.addEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.addEventListener(MouseEvent.MOUSE_OVER,StopOver);
SoundMixer.soundTransform = new SoundTransform(1);
btnstop.visible=true;
btnplay.visible=false;
}
}
function StopRadio(evt:Event):void
{
if(isplay==1)
{
btnstop.removeEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.removeEventListener(MouseEvent.MOUSE_OVER,StopOver);
btnplay.addEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.addEventListener(MouseEvent.MOUSE_OVER,PlayOver);
SoundMixer.soundTransform = new SoundTransform(0);
isplay=0;
btnstop.visible=false;
btnplay.visible=true;
}
}
/*var bgslider = new MovieClip();
trace(bgslider.name);
for(var i:uint=0;i<bgslider.numChildren;i++){
trace(bgslider.getChildAt(i).name);
}*/
bgslider.mc.addEventListener(MouseEvent.MOUSE_DOWN,StartDrag);
bgslider.mc.addEventListener(MouseEvent.MOUSE_UP,StopDrag);
function StartDrag(event:MouseEvent):void
{
bgslider.mc.startDrag(true,new Rectangle(152,37,182,0));
}
function StopDrag(event:MouseEvent):void
{
bgslider.mc.stopDrag();
}
please give the correct answer anyone, thanks advance
That TypeError is usually an indication that you misspelled an object reference or didn't give it one at all.
Double check your bgslider and mc reference in the property inspector. Make sure it's not called bg_slider, bgSlider or something like that.

How can I record audio in a Air Mobile App?

I had searched for a long time and didn't found anything about it. Is it possible?
AIR2 version of of the Galaxy-Tab1 device worked well when tested on 3years ago.
refer a following my code. I'll probably work well. Trust me on that.
Framework used here is the link.
WAVWriter:
WAVWriter
ShineMP3Encoder:
ShineMP3Encoder
This code is Skeleton, but Worked fine.
import com.adobe.audio.format.WAVWriter;
import fr.kikko.lab.ShineMP3Encoder;
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.utils.ByteArray;
import flash.events.Event;
var mp3encoder:ShineMP3Encoder;
var microphone:Microphone;
var isRecording:Boolean=false;
var soundRecording:ByteArray;
function startMicRecording():void
{
isRecording=true;
soundRecording = new ByteArray();
microphone=Microphone.getMicrophone();
microphone.rate=44;
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
function stopMicRecording():void {
isRecording=false;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
soundRecording.position=0;
convert2MP3();
}
function gotMicData(micData:SampleDataEvent):void
{
soundRecording.writeBytes(micData.data);
}
function convert2MP3():void
{
var wavWrite:WAVWriter = new WAVWriter();
wavWrite.numOfChannels=1;
wavWrite.sampleBitRate=16;
wavWrite.samplingRate=44100;
var wav:ByteArray = new ByteArray();
wavWrite.processSamples(wav, soundRecording, 44100,1);
wav.position=0;
/*
If the process is compressed into mp3 if you have big problems,
just as .wav format save. following code:
var file:FileReference = new FileReference();
file.save(wav,"your_file_name.wav");
*/
mp3encoder=new ShineMP3Encoder(wav);
mp3encoder.addEventListener(Event.COMPLETE, onEncoded);
mp3encoder.start();
}
function onEncoded(e:Event):void
{
mp3encoder.mp3Data.position=0;
mp3encoder.saveAs("your_file_name.mp3");
}