compiler errors when loading in XML data into flash - actionscript-3

Hi im trying to learn flash actionscript 3.0 basically i just want to learn how to put 1 simple picture into a flash document using XML so far ive got
<Gallery>
<IMAGE TITLE="Picture">Desert.jpg</IMAGE>
</Gallery>
thats my XML code DESERT is a picture on my laptop from the sample pictures
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var myXML:XML;
var imageLoader:URLLoader = new URLLoader();
imageLoader.load(new URLRequest("pictest.xml"));
imageLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML);
this is my flash code when i run it i get a ton of errors which im confused about im new to this so any help would be appreciated also the myLoader is a textarea box with the instance name imageLoader
compiller errors im getting are :
A conflict exists with the definition myXML in namespace internal
A conflict exists with the definition imageLoader in namespace internal
duplicate function definition
Thanks in advance Rhys

What all these errors say is that you have written your code (same code you posted) more then once. In AS3 it is illegal (semi-legal in certain circumstances) to declare same variable or function more then once in the same scope - this is why you get the error.
So, check that other frames don't declare myXML, imageLoader and processXML again.

Related

StageWebView in an AS3-Script

I allreday read a lot of helpful stuff in that forum. Now it's my first time I ask for specific help.
I'm pretty new to Flash and have a problem I struggle for more then a week now. The most efficient and elegant way for my problem is to put a StageWebView-Call into an as-File.
That would be the plan:
In my flash-File: Show a PDF document "xyz" and put it on the stage.
I alreday tried it with Switch-Case - But then I have trouble to get rid of the PDF's.
That was my Idea:
First the new as-File...
package {
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 class mypdf {
public var MyWebView:StageWebView
public var file:String
public var pdf:File
public function mypdf(ActFile:String) {
MyWebView = new StageWebView();
file = ActualFile; //MARKING #1
pdf = File.applicationDirectory.resolvePath(file);
MyWebView.stage = stage; //MARKING #2
MyWebView.viewPort = new Rectangle (200, 200, 400, 400);
MyWebView.loadURL(pdf.nativePath);
}
}
}
Than I want to call that in my flash-File...
stop();
var mynewpdf:mypdf = new mypdf("test.pdf");
Two erros are shown:
1120: Access of undefined property error ActualFile (at Marking #1)
1120: Access of undefined property error Stage (at Marking #2)
With a lot more work I could avoid the first error by defining a lot of different as-Scripts for each pdf.
My main problem is the second error.
It would be really nice if someone had any good ideas.
Bye,
Stephan
The second error means that you need to pass the stage to the web view. Either pass it to mypdf class as parameter, or make mypdf DisplayObject (extend Sprite for example) and add it to stage.
I'm not sure this will solve your issue anyways - I think StageWebView can simply display html. The PDF is displayed in your browser because an external plugin for that is launched.
In AIR the situation seems different: http://sujitreddyg.wordpress.com/2008/01/04/rendering-pdf-content-in-adobe-air-application/
StageWebView is wont support for nativePath, instead of using this, you can try with pdf.url. And StageWebView also having support for open .pdf files.
public function mypdf(ActFile:String) {
MyWebView = new StageWebView();
file = ActualFile; //MARKING #1
pdf = File.applicationDirectory.resolvePath(file);
MyWebView.stage = stage; //MARKING #2
MyWebView.viewPort = new Rectangle (200, 200, 400, 400);
addChild( MyWebView );
MyWebView.loadURL(pdf.url);
}
Because, StageWebView will support file:/// format, but in nativePath we got C://.., so, this will help you. Or
Simply convert your StageWebView to Display object, and then added it to your container by using addElement().
You can convert it by,
var _view:SpriteVisualElement = new SpriteVisualElement();
_view.addChild( MyWebView);
this.addElement( view );
To test by, simply call this method in added_to_stage method to test if stage is having or not. This error will come if stage is not setted means also.

Saving customized movieclip as an image to local disk (diy generator)

dropbox.com/s/77euop1luqjreos/FINAL.fla
Ok i just gave up with this already. I cant think of any way to save the image created by a user. Its hard to explain but please check out the fla file of my work. Basically its a diy generator. The only thing missing is a save function. Ive read filereference but its always in a document class. My code is in the timeline. Please help I'm really stuck.
edit: I got a download button that is working now!! But it only saves a small part of the movieclip: Imgur
In order to create images, you need to access the pixel data of the MovieClip object. The data can be obtained by rendering a MovieClip into a BitmapData object and using this data, you can write your own encoder to convert it to any image format you’d like. Writing such encoder is not a trivial task and requires understanding of the image format algorithm, or you can use pre-written libraries. You can download the PNGEncoder and JPGEncoder , which is part of as3corelib, an open source project library.
Using the JPGEncoder, we can convert DisplayObject into ByteArray, suitable for saving into file. If using the JPGEncoder, it’ll look like this:
import com.adobe.images.JPGEncoder;
var jpgEncoder:JPGEncoder = new JPGEncoder(quality);
//remember bitmapData here is just an example (do not try to compile this code without declare this particular variable)
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
With the PNGEncoder, it’ll look like this:
import com.adobe.images.PNGEncoder;
//remember bitmapData here is just an example (do not try to compile this code without declare this particular variable)
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
Saving Into User’s Hard Drive
Using the FileReference.save() function, we can prompt the user to save the file with the following call.
var fileReference:FileReference=new FileReference();
//in case of JPGEncoder
fileReference.save(byteArray, ".jpg");
With the two combined, here’s an example how to use:
//remember to import
import flash.net.FileReference;
import com.adobe.images.JPGEncoder; //or import com.adobe.images.PNGEncoder;
import flash.utils.ByteArray;
import flash.display.BitmapData;
//where mc_canvas will be your MovieClip instance name
var bitmapData:BitmapData = new BitmapData(mc_canvas.width, mc_canvas.height);
bitmapData.draw(mc_canvas);
var jpgEncoder:JPGEncoder = new JPGEncoder(quality_slider.value);
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
//if you want to use PNGEncoder
//var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
var fileReference:FileReference = new FileReference();
fileReference.save(byteArray, ".jpg");

ActionScript code problems

I have only recently started to learn ActionScript 3.0 I was practising in Flash and i ran into this problem:
Scene 1, Layer 'Layer 1', Frame 1, Line13 1119: Access of possibly undefined property dosomething through a reference with static type flash.net:SharedObject.
What i am tring to do is use the SharedObject.send method to send a message obviously. I have edited some server side code in my main.asc file. And i am trying to pass in the doSomething function but i get that compile error.
Any advice would be appreciated for a novice like myself.
The code is below:
import flash.net.NetConnection;
import flash.net.SharedObject;
var nc:NetConnection = new NetConnection();
nc.connect("rtmp:/exampletest/");
var so:SharedObject = SharedObject.getRemote("foo", nc.uri, true);
so.connect(nc);
so.dosomething = new function(str) {
If you want to pass a function between SWFs, attach the function to the .data member of the SharedObject returned by SharedObject.getLocal/Remote, not the SharedObject itself.
So:
so.data.doSomething = yourFunction
...should work. I'm not exactly sure what you're trying to achieve, does this sound like a solution?

Im trying to write a program which loads external resources with metadata tags in As3

ive been given some work to do but i cant seem to understand why its not working..
I think im using a wrong approach,
Im trying to load a picture and a movieclip on the same stage..
Though ive managed to display a picture, but when i try to display a MovieClip.. There arent errors though when i run i get the following:
TypeError: Error #1034: Type Coercion failed: cannot convert LoadingFiles_MovingStars1#2aba161 to flash.display.Bitmap. at LoadingFiles()[C:\Users\user\Adobe Flash Builder 4.5\LoadingFiles\src\LoadingFiles.as:28
Here is the code,
package
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
[SWF(width = "800", height = "600", frameRate = "30", backgroundColor="#FFFF00")]
public class LoadingFiles extends Sprite
{
[Embed(source="/../assets/Head.jpg")]
protected var MovingStars:Class;
[Embed(source="/../assets/water1.mp4", mimeType = "application/octet-stream")]
public var MovingStars1:Class;
public function LoadingFiles()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
// swf
var myStars:Bitmap = new MovingStars();
var myPic:Bitmap = new MovingStars1(); //
var yourPic:MovieClip = new MovingStars1();
myStars.x = (stage.stageWidth-myStars.width)/2;
myStars.y = (stage.stageHeight-myStars.height)/2;
addChild(myPic as MovieClip);
addChild(yourPic);
addChild(myStars);
}
}
}
Now ive written that code, but it doesnt work..
Im really stressing because im falling behind by a bit in class..
Help would greatly appreciated.
Thank you.
You're trying to instantiate an embedded .mp4 file as a Bitmap or a MovieClip. That's not possible, you need to create a video player or use an already existing videoplayer component.
Here's a more in-depth answer on that:
How to make an AS3 Flash video player?
When you embedded image
[Embed(source="/../assets/Head.jpg")]
protected var MovingStars:Class;
Your MovingStars is BitmapAsset class. This is class included in Flex SDK. So you need preload Flex SDK rsl's. Or configure Flex SDK libraries linking as merge in to code.
What IDE are you using?

Xml not loading into flash properly

Hi im trying to learn flash actionscript 3.0 basically i just want to learn how to put 1 simple picture into a flash document using XML so far ive got
<Gallery>
<IMAGE TITLE="Picture">Desert.jpg</IMAGE>
</Gallery>
thats my XML code DESERT is a picture on my laptop from the sample pictures
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("pictest.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.*);
}
this is my flash code when i run it i get a ton of errors which im confused about im new to this so any help would be appreciated also the myLoader is a textarea box with the instance name myLoader
Thanks in advance Rhys
Probably you must change the order. First the event listener and after that the event.
myLoader.addEventListener(Event.COMPLETE, processXML);
myLoader.load(new URLRequest("pictest.xml"));
Greetings,