How to change the Adobe Flash Player version in Adobe Flash CS3 - actionscript-3

I want to create a flash application that records audio through the user's microphone and then make an upload to the server, in order to do that I've found this code:
import flash.media.Microphone;
import flash.events;
const DELAY_LENGTH:int = 4000;
var mic:Microphone = Microphone.getMicrophone();
mic.setSilenceLevel(0, DELAY_LENGTH);
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
function micSampleDataHandler(event:SampleDataEvent):void {
while(event.data.bytesAvailable) {
var sample:Number = event.data.readFloat();
soundBytes.writeFloat(sample);
}
}
I couldn't test it yet, since it throws me this compiling error:
"1046:Couldn't find type or is not a constant during compiling time: SampleDataEvent"
After a research I've found that I have to update the Flash player version to compile to 10.0.0 in order to make it work, but I don't know how to do that. My IDE is the Adobe Flash CS3 Portable and most of the examples are for other IDEs like Flex, how can I do that?

You are not importing flash.events.SampleDataEvent and soundBytes is not defined in the micSampleDataHandler handler.
import flash.media.Microphone;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
const DELAY_LENGTH:int = 4000;
var mic:Microphone = Microphone.getMicrophone();
mic.setSilenceLevel(0, DELAY_LENGTH);
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
function micSampleDataHandler(event:SampleDataEvent):void {
var soundBytes:ByteArray = new ByteArray();
while(event.data.bytesAvailable) {
var sample:Number = event.data.readFloat();
soundBytes.writeFloat(sample);
}
}

Related

flash as3 trying to play audio from external swf and getting message "Call to a possibly undefined method"

I'm able to load graphics from an external library with no problems, but for some reason all of the audio will not load/play.
Here's the loader class I'm using...
package
{
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.Font;
public class LoadLibrary extends MovieClip
{
private var gear:MovieClip = new mcGear();
private var txtLoading:BlankClip;
private var _gameLib:String = "";
private var _Impact:Font = new Impact();
public function LoadLibrary(gameLibrary:String)
{
_gameLib = gameLibrary;
addChild(gear);
gear.x = 512;
gear.y = 384;
gear.alpha = .2;
gear.scaleX = .33;
gear.scaleY = .33;
txtLoading = new BlankClip(_Impact, "LOADING...", -400, -60, 800, 120, 26, "center", 5);
addChild(txtLoading);
txtLoading.x = 512;
txtLoading.y = 525;
txtLoading.alpha = .2;
var request:URLRequest = new URLRequest(_gameLib);
LoadVars.LIBLOADER.contentLoaderInfo.addEventListener(Event.COMPLETE, gameLibraryLoaded);
LoadVars.LIBLOADER.load(request);
}
private function gameLibraryLoaded(e:Event):void
{
removeChild(gear);
removeChild(txtLoading);
LoadVars.LIBLOADER.contentLoaderInfo.removeEventListener(Event.COMPLETE, gameLibraryLoaded);
var loaderInfo:LoaderInfo = LoaderInfo(e.currentTarget);
LoadVars.APPDOMAIN = loaderInfo.applicationDomain;
dispatchEvent(new GameEvents(GameEvents.LIBRARY_LOADED));
}
}
}
and the functions in my main class...
private function loadLib():void
{
_loadGraphics = new LoadLibrary("Elemental_Library.swf");
addChild(_loadGraphics);
_loadGraphics.addEventListener(GameEvents.LIBRARY_LOADED, test);
}
private function test(e:GameEvents):void
{
trace("LOADED");
var music:Sound = new GameMusic();
music.play();
}
Everything works fine until I try music.play and I get "1180: Call to a possibly undefined method GameMusic." I've tried several other audio clips and I get the same message. I tried creating a new library and imported just one audio file, same message. I verified I'm using the correct linkage names and the crazy part is that all of the movie clips load just fine from the same library.
Changed test to...
private function test(e:GameEvents):void
{
trace("LOADED");
var musicClass:Class = Class(LoadVars.APPDOMAIN.getDefinition("GameMusic"));
var music:Sound = Sound(new musicClass()); music.play();
}
I knew it was something stupid :P

how to embed pdf file in flash based application (IOS and android)

I’m creating application for android and IOS using FLASH CS5.5
I want to open pdf file when I click on the button. I try to use this code but is not working
package
{
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowSystemChrome;
import flash.display.NativeWindowType;
import flash.display.NativeWindow;
import flash.events.Event;
import flash.display.SimpleButton;
public class bpdf extends SimpleButton
{
public function bpdf()
{
// constructor code
var htm:HTMLLoader= new HTMLLoader();
htm.load(new URLRequest("test.pdf"));
var init:NativeWindowInitOptions= new NativeWindowInitOptions();
init.systemChrome = NativeWindowSystemChrome.STANDARD;
init.type = NativeWindowType.NORMAL;
var win:NativeWindow = new NativeWindow(init);
win.stage.addChild(htm);
win.width = stage.stageWidth;
win.height = stage.stageHeight;
win.activate();
htm.width = win.width;
htm.height = win.height;
win.addEventListener(Event.CLOSE, onCloseEvent);
}
function onCloseEvent(e:Event)
{
trace("window closed");
}
}
}
after publishing with “PLYER: AIR FOR ANDROID” then I got these error message in output
[SWF] link2.swf - 2907 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at bpdf()[C:\Users\HP\Desktop\PDF Link\Link_2\bpdf.as:30]
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
I also convert my file in APK and check in my android device but same problem when I click on the button, nothing happened
I make my APK file without include pdf and with include pdf
Include my pdf file using this way:: Publish setting > PLAYER: AIR FOR ANDROID – setting > Included files: test.pdf
Try with this
If you want to open pdf use StageWebView instead of HTMLLoader class. Like this
protected function loadPDF(event:MouseEvent):void {
var file:String = "Lorem_Ipsum.pdf";
var yOffset:Number = 40;
var stageWebView:StageWebView = new StageWebView();
stageWebView.stage = stage;
stageWebView.viewPort = new Rectangle(0, yOffset, 500, 500 - yOffset);
var pdf:File = File.applicationStorageDirectory.resolvePath(file);
stageWebView.loadURL(pdf.nativePath);
}
source : more details
Also look at stack overflow display-local-pdf

embedded font flash.text.engine

I've completely run out of ideas on this. It follows, and is part of my previous question:
embedding a font in a swf using as3
I just don't seem to be able to get the flash.text.engine to use my embedded font. NB the font has to be loaded into the application (as embedded in swf) after the user has chosen the two languages (for translation to and from). There seems to be a little info implying that it is now necessary to use the fontswf application which is in the sdk. I have tried this and produced loadable swf files but I can't find any info on how these are then loaded (i.e. the getDefinition and registerFont bits below don't work as there are no classes in these swf) and applied to text.engine objects. The source for the embedding is in my answer to my question above. This is a test as3 which demonstrates how it doesn't work!
package
{
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.engine.ElementFormat;
import flash.text.engine.FontDescription;
import flash.text.engine.TextBlock;
import flash.text.engine.TextLine;
import flash.text.engine.TextElement;
import flash.net.URLRequest;
import flash.text.Font;
public class Main extends Sprite
{
private var loader:Loader;
private var tl:TextLine;
public function Main():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,fontLoaded);
loader.load(new URLRequest("EnglishF.swf"));
}
private function fontLoaded(evt:Event):void {
var FontClass:Class
FontClass = evt.target.applicationDomain.getDefinition("EnglishF") as Class;
try {
Font.registerFont(FontClass.myFont);
trace("successfully loaded " + FontClass);
// gives 'successfully loaded EnglishF'
} catch (err:Error) {}
var fontList:Array = Font.enumerateFonts();
for (var i:int = 0; i < fontList.length; i++) {
trace(fontList[i].fontName, fontList[i].fontType);
// gives 'EnglishF embeddedCFF'
}
var block:TextBlock = new TextBlock();
var font:FontDescription = new FontDescription("EnglishF");
var formt:ElementFormat = new ElementFormat(font, 30);
trace(FontDescription.isFontCompatible("EnglishF","normal","normal"), formt.fontDescription.fontName);
// gives 'true EnglishF'
formt.color = 0x882233;
var span:TextElement = new TextElement("Hello World. This is certainly NOT in the Font provided!", formt);
block.content = span;
tl = block.createTextLine();
tl.x = 10;
tl.y = tl.ascent + 10;
addChild(tl);
}
}
}
Am I doing anything wrong, or is this impossible?
Hopefully this will help. Under this line:
var font:FontDescription = new FontDescription("EnglishF");
add the following line:
font.fontLookup = FontLookup.EMBEDDED_CFF;
This will let the text framework know that you're using a CFF font (used in the new text framework), instead of a regular embedded font (used in TextFields).
Hope this helps.
Jordan

Converting AS3 to AS2

I have this problem. Have a banner which is code with AS3, and our system only displays banners up to Flash Player 9. But Flash Player 9 does not support AS3 . So is there a way to do it on the easy way? Or I have to rewrite it on AS2 ? Here is the code.
import flash.events.Event;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
cierre.gotoAndStop(1);
SoundMixer.soundTransform = new SoundTransform(0);
video_player.autoPlay = true;
video_player.source = "video_500x374.f4v";
video_player.addEventListener(Event.COMPLETE, finVideo);
stop();
b2_btn.buttonMode = true;
buttonclose.addEventListener(MouseEvent.CLICK,buttoncl);
function buttoncl(e:Event):void{
video_player.stop();
this.gotoAndStop(1);
}
var paramList:Object = this.root.loaderInfo.parameters;
b2_btn.addEventListener(MouseEvent.CLICK, openURL);
function openURL(evtObj:MouseEvent):void {
var request:URLRequest = new URLRequest(paramList["clickTag"]);
navigateToURL(request, "_blank");
}
function aBanner1(e:Event):void{
video_player.stop();
this.gotoAndStop(1);
}
function finVideo(e:Event):void{
video_player.stop();
cierre.play();
}
function setMute(vol) {
var sTransform:SoundTransform = new SoundTransform (0,1);
sTransform.volume = vol;
SoundMixer.soundTransform = sTransform;
}
var Mute:Boolean = false;
mutebutton.addEventListener (MouseEvent.CLICK,toggleMuteBtn);
function toggleMuteBtn (event:Event) {
if(Mute) {
Mute = false;
setMute(0);
}else{
Mute = true;
setMute(1);
}
}
You need to use the AS2 FLV Playback component. You should start with a clean new AS2 fla and start copying everything over except the components stuff.

Don't load xml data to list when publishing by Flash CS 5.5

I build a flash video player which works fine when exported to swf. However when I publish it (F12) does not loading the xml file. As a result video player stuck to frame 2 (where presented a List with video titles and with click on title plays the specific video). The xml link does not ends to .xml. Here is my code about xml loading. I try to change the Flash Player from 10.2 to 9 but I have the same problem.In addition some buttons in frame 2 does not works I suppose because of "Stuck" from xml loading.( Work fine when exported in swf!)
Flash Player version: 10.2, Actionscript:3.0, Flash Professional CS 5.5, fps:24, size: 850px(w)x480px(h). Code from FRAME 2 . Thanks for your time guys.
Security.allowDomain( "*" );
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import fl.controls.Label;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
var request:URLRequest = new URLRequest("http://www.olympiacos.org/feeds/videos")
loader.load(request);
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError)
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus2)
function onIOError(evt:IOErrorEvent){
trace("IOError: "+evt.text);
}
function onHTTPStatus2(evt:HTTPStatusEvent){
trace("HTTPStatus: "+evt.status);
}
function onSecurityError(evt:SecurityErrorEvent){
trace("SecurityError: "+evt.text);
}
function handleComplete(event:Event):void
{
try
{
var rawXML:XML = new XML(event.target.data);
trace(rawXML);
var list:XMLList = rawXML.channel.item;
for (var i:uint=0; i<list.length(); i++)
{
t_text.text = list.title.text()[i];
var data1:String = (list[i].description);
var srcRegExp:RegExp = /src="(.*?)"/;
var data2:String = srcRegExp.exec(data1)[1];
var lwr = data2.search(/1_/i);
var her = lwr + 10;
var data3 = data2.substring(lwr,her);
trace("Entry Id"+i+": "+data3);
List1.addItem({label:list.title.text()[i],data:data3});
}
}
catch (e:TypeError)
{
//Could not convert the data, probavlu because
//because is not formated correctly
trace("Could not parse the XML");
trace(e.message);
}
}
List1.addEventListener(Event.CHANGE, itemChange);
openbtn.addEventListener(MouseEvent.CLICK, opentween);
closebtn.addEventListener(MouseEvent.CLICK, closetween);
closebtn.visible=true;
openbtn.visible=false;
function itemChange(e:Event):void
{
if ( currentFrame == 2)
{
trace("Video selected");
gotoAndPlay(3);
}
t_text.text = List1.selectedItem.label;
var videoslcd = List1.selectedItem.data;
}
stop();
what;s your publishing setting regarding playback security? Should be "Access network only"