Display XML content in Flash movie as Text - actionscript-3

Inside a Flash Movie (Actionscript 3) I need to display the content of a XML file.
I am passing the url of the file as a parameter. So I am using the following:
var file : XML;
var url = loaderInfo.parameters.url;
var loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(url));
function onLoadComplete(e:Event){
file = new XML(e.target.data);
} // OnLoadComplete
How can I display the entire content of the XML file, as text, in the Flash Movie?
Probably the content will be big so I would like to have scroll bars.
Thank You,
Miguel

try this for example.
//... previous code
loader.load(new URLRequest(url));
var myTextBox:TextField = new TextField();
myTextBox.width = 200;
myTextBox.height = 150;
myTextBox.multiline = true;
myTextBox.wordWrap = true;
myTextBox.background = true;
myTextBox.border = true;
addChild(myTextBox);
function onLoadComplete(e:Event){
file = new XML(e.target.data);
myTextBox.text = file.toString();
}

Related

show dimension of flv in text field

Below is my basic code, im loading a flv video using flvplayback.
i need the features of flvplayback compulsorily.
I have finished loading flv video sucessfully.
Now im stuckup with showing the source video files original dimension in a text field.
How should proceed further from here. Please guide me......
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
import fl.video.*;
stop();
var rmys01:FLVPlayback = new FLVPlayback();
rmys01.source = "rhym01.flv";
rmys01.skin = "MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf";
rmys01.autoPlay = true;
rmys01.fullScreenTakeOver = false;
rmys01.scaleMode = "maintainAspectRatio";
rmys01.setSize((stage.stageWidth/1.03), (stage.stageHeight/1.03));
rmys01.x = (stage.stageWidth/2) - (rmys01.width/2);
rmys01.y = (stage.stageHeight/1.1) - (rmys01.height/1.1);
addChild(rmys01);
setChildIndex(rmys01,1);
Did you set client for the NetStream? Because, all work ok.
Here is an example:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var client: Object = {};
client.onMetaData = function(data:Object):void{
//Display width and height
var textField: TextField = new TextField();
textField.autoSize = TextFieldAutoSize.LEFT;
textField.defaultTextFormat = new TextFormat("Arial", 28);
textField.text = "Width: " + data.width + ", Height: " + data.height;
addChild(textField);
}
ns.client = client;
ns.play("path/to/Video");
var myVideo:Video = new Video();
myVideo.attachNetStream(ns);
addChild(myVideo);
For debugging purposes place trace (trace("There is MetaData!");) to the onMetaData handler, check, if it triggers.
For FLVPlayback, you should subscribe for VideoEvent.READY:
rmys01.addEventListener(VideoEvent.READY, onReady);
function onReady(e:VideoEvent):void {
trace("READY");
var flvPlayback:FLVPlayback = e.target as FLVPlayback;
var metaData:Object = flvPlayback.metadata as Object;
trace("height: "+metaData.height);
trace("width: "+metaData.width);
trace("duration: "+metaData.duration);
}
If you are coding in Flash IDE, there will be a problem with VideoEvent, so you should use fully qualified class (fl.video.VideoEvent), if not, IDE will try resolve it to the flash.events.VideoEvent:
rmys01.addEventListener(fl.video.VideoEvent.READY, onReady);
function onReady(e:fl.video.VideoEvent):void {
//Handler code
}

AS3 - navigateToURL issue

I have below code:
botton_1.addEventListener(MouseEvent.MOUSE_UP, onClick);
function onClick(e:MouseEvent):void {
var url:String = "http://www.xxxxxxxxxx.com/signInDetail";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.query = ta.text;
variables.packageId = 1;
variables.update = "askADoctorSaveQuery";
variables.task = "CHAT_PRE_ACTIONS_WITHOUT_PACKAGEID";
variables.query = ta.text;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,compleHandler);
loader.load(request);
}
function compleHandler(event:Event):void {
var click_url2:String = "http://www.xxxxxxxx.com/ask-doctor-online";
var request2:URLRequest = new URLRequest(click_url2);
navigateToURL(request2, "_blank");
}
After the first request is loaded and compleHandler is called, the navigateToURL method opens the url in a popup instead of new tab. I am not sure what is the issue.
PLease help...
Replace this line. This loads it into a new window.
navigateToURL(request2, "_blank");
You have two other options:
In parent frame :
navigateToURL(request2, "_parent");
Replace current page :
navigateToURL(request2, "_self");
EDIT
After rechecking, I believe opening a window in a new tab is a user preference for the browser. There seems to be no way that a developer can control this. In IE 8 for example:
http://www.computershopper.com/feature/50-windows-7-tips-tweaks-and-secrets/open-a-link-in-a-new-tab-in-internet-explorer-8
navigateToURL(request2, "_self");

Load external swf into bytearray with adobe flash

How can I load external swf into bytearray with adobe flash AS3..
Here is my code..
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
my_url1.method = URLRequestMethod.GET;
my_url1.contentType = "application/x-shockwave-flash";
var urlloader:URLLoader = new URLLoader(my_url1);
var myByteArray:ByteArray = new ByteArray();
urlloader.data = myByteArray;
It not works well. But it isn't give any error. How can I fix this problem?
You should listen for COMPLETE event and set the data format to BINARY:
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
var urlloader:URLLoader = new URLLoader(my_url1);
urlloader.dataFormat = URLLoaderDataFormat.BINARY;
urlloader.addEventListener(Event.COMPLETE, function(event:Event):void
{
var myByteArray:ByteArray = URLLoader(event.target).data as ByteArray;
trace(myByteArray.length);
});

AlivePDF not writing out text using addText(). Nothign I'm trying is working. What am I missing?

No matter what I try I can't write anything to a PDF that can be seen, although the text is there when viewing the resultant PDF in Notepad. What am I not doing? Here's a code snippet. the variable tf is a TextField defined in the class. This works in the SWF, just not with PDF.
private function onButtonClick(e:MouseEvent):void {
tf.text = "Hey, you clicked the button!";
myPDF = new PDF(Orientation.PORTRAIT, Unit.INCHES, Size.A4);
myPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE)
myPDF.addPage();
myPDF.addText(tf.text, 20, 20 );
var filename:String = "Test-file.pdf";
var f:FileStream = new FileStream();
var file:File = File.userDirectory.resolvePath(filename);
f.open(file, FileMode.WRITE);
var bytes:ByteArray = myPDF.save(Method.LOCAL);
f.writeBytes(bytes);
f.close();
}

Actionscript 3: Converting bytearray to PNG and display on the scene

I'm getting getting a PNG image stored in SQL through a WCF get call. The image is encoded as a base64 string and delivered to my AS3 code. I need to extract the image from the data and show it on the scene.
Among other things, I have also tried this...
var imgArray:ByteArray = Base64.decodeToByteArray(responseXML.ImageObject);
var myRect:Rectangle = new Rectangle(100,100,200,200);
var bmd:BitmapData = new BitmapData(200,200,true,0xAAAAAAAA);
bmd.setPixels(myRect, imgArray);
var image:Bitmap = new Bitmap(bmd,"auto",true);
this.addChild(image);
but to no avail.
HELP!
why don't you use a loader and loadbytes? It's native.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoad)
loader.loadbytes(byteArray);
private function handleLoad(e:Event):void {
var loader:Loader = e.currentTarget as Loader;
// removelistener,etc
trace(loader.content as Bitmap);
}
The problem with your code is that PNG is compressed, bitmap is uncompressed.
I used DanielH's input and got the image to load on my stage. Here is what I did in the event handler function...
function ImageLoaded(e:Event):void
{
var bmd:BitmapData = new BitmapData(imageLoader.ImageLoader.width,imageLoader.ImageLoader.height,true, 0xFFFFFF);
bmd.draw(imageLoader.ImageLoader);
var image:Bitmap = new Bitmap(bmd,"auto",true);
image.width=40;
image.height=40;
if(!CheckAndStoreImageIDKey(imageLoader.ImageID))
{
Images[imageLoader.ImageID] = image;
}
}
Try PNGDecoder (http://www.ionsden.com/content/pngdecoder)
import ion.utils.png.PNGDecoder;
var bmd:BitmapData = PNGDecoder.decodeImage(imgArray);