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

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

Related

ActionScript 3.0 sound not working

So having trouble making sound on keyboard press
I have the imports:
import flash.net.URLRequest;
import flash.media.Sound;
I have the variables
private var soundDownRequest:URLRequest = new URLRequest ("SoundDown.mp3");
private var downSound:Sound = new Sound (soundDownRequest);
and the event listener
private function keyDownHandler(evt:KeyboardEvent):void
{
if (evt.keyCode == 40)//ascii for down arrow
{
downSound.play();
}
}
The sound folder is in the same folder as the .as, its also in the library of the fla, yet it still doesn't work. Any idea why?
Thank you.
Update:
I got the sound to work but not using the external method I was trying to do above.
Had to do it internally.
so you need:
import flash.media.SoundChannel;
-Then you need to make sure your sound file is in your fla library.
once its in the library
-Right click > properties
-Select the Action Script Tab
-Check "export for action script"
-Give the class a name in accordance to the sound
-press ok
add this variable (your will be different):
private var downSound:TheDownSound = new TheDownSound();
downsound is the selected name of the variable, and TheDownSound is the name of the class (the one made earlier for the sound file)
then add this to where you want the sound to play:
var myDownSound:SoundChannel = downSound.play();
Do this if you cant get it working externally like me.
for a better explanation watch this guys youtube video:
https://www.youtube.com/watch?v=SZpwppe7yGs
Your code is working perfectly ok if you put your .mp3 file in the same folder as the output .swf, not near the class .as source file (because its the swf file loading the sound, so the path must be relative to it)
public class ASEntryPoint extends Sprite {
private var soundDownRequest:URLRequest = new URLRequest ("click.mp3");
private var downSound:Sound = new Sound (soundDownRequest);
public function ASEntryPoint() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
}
private function keyDownHandler(evt:KeyboardEvent):void{
if (evt.keyCode == 40) {
downSound.play();
}
}
}
You need to load the external file, which is asynchronous operation. Then you track the loading event and if it all goes normally you can play your loaded sound.
import flash.events.SecurityErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.Event;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
// Keep the sound loader from being garbage collected.
var soundLoader:Sound;
function loadSound(url:String):void
{
var aRequest:URLRequest = new URLRequest(url);
soundLoader = new Sound();
// Handle the normal loading.
soundLoader.addEventListener(Event.COMPLETE, onLoaded);
// Handle the error cases.
soundLoader.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);
soundLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError, false, 0, true);
soundLoader.load(aRequest);
}
var audioChannel:SoundChannel;
function onLoaded(e:Event):void
{
// Sound is available here for playback.
audioChannel = soundLoader.play();
}
function onError(e:Event):void
{
trace(e);
}
You can also handle your sound as a streaming audio, but I worked with that years ago in AS2 so I cannot help here. Still, internet suggests a link: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d22.html

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();

How to change the Adobe Flash Player version in Adobe Flash CS3

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);
}
}

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

loading external movie as2 wrapper

Load AS2 SWF Into AS3 SWF and pass vars in URL
I'm trying to load in a as3 file an external as2 swf file (of which I dont have access to fla file). According to the explanation given in the link above, the solution would be to use a as2 wrapper to the original as2 file (and establish a localconnection between the the as3 and as2 files). I've tried to do that, but although the movie seems to load in my as3 file, it doesnt start, doesnt play and gets stuck in the first frame. How do I play the movie (as well as load it)? Thanks for your help.
My as3 file is:
import com.gskinner.utils.SWFBridgeAS3;
var loader = new Loader()
loader.load(new URLRequest("as2_test.swf"));
addChild(loader);
var sb1:SWFBridgeAS3 = new SWFBridgeAS3("test",this);
my as2 file is:
import com.gskinner.utils.SWFBridgeAS2;
var sb1 = new SWFBridgeAS2("test",this);
sb1.addEventListener("connect",this);
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(this);
loader.loadClip("digestive.swf", mainLoader_mc);
EDIT: I keep having this problem. This is what I have so far:
as2 file - as2test.fla (this needs to download another as2 file -digestive.sfw and acts as wrapper to establish connection between the original as2 file and the main as3 file)
import com.gskinner.utils.SWFBridgeAS2;
var sb1 = new SWFBridgeAS2("test",this);
sb1.addEventListener("connect",this);
var my_pb:mx.controls.ProgressBar;
my_pb.mode = "manual";
this.createEmptyMovieClip("img_mc22", 999);
var my_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip):Void {
my_pb.label = "loading: " + target_mc._name;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
var pctLoaded:Number = Math.ceil(100 * (numBytesLoaded / numBytesTotal));
my_pb.setProgress(numBytesLoaded, numBytesTotal);
trace(pctLoaded);
};
my_mcl.addListener(mclListener);
my_mcl.loadClip("digestive.swf", img_mc22);
stop();
as3 file (this plays the as2 wrapper):
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("as2test.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
stop();
In the as2 wrapper file, the original movie plays until a certain frame; in the as3 file, the as2 wrapper file only plays the first frame. What do I have to do?????