Xml not loading into flash properly - 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 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,

Related

how can I add display.movieclip(include as3 inside and embedded video, means lots of video frames) to starling?

I created a movieclip, I imported a video inside it ,as3 code that loads an image, and animate that image on the video.I use as3 codes like below
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
var imgLoader:Loader = new Loader();
imgLoader.load(new URLRequest(File.applicationStorageDirectory.resolvePath("imagem.jpeg").url));
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded1);
because of performence issues, I choose Starling to record that movieclip. and I use below code for that,
var kmcv2:mcv2 = new mcv2();
kmcv2.x=304;
kmcv2.y=208;
kmcv2.width=750;
kmcv2.height=382;
Starling.current.nativeOverlay.addChild(kmcv2);
but this code does not record it, because my movieclip is on the top.
stage.drawToBitmapData( _bmp );
how can I handle it?
thank you.

Can't have 2 dynamic text fields AS3

This is not a specific situation, this is something that happens a lot to me.
Whenever I have dynamic text (that changes through code, of course) everything works fine.
However, when I add a second Dynamic text, both of them do not show.
An example scenario would be:
textfield1.text="hello";
and on the next frame
textfield2.text="goodbye";
no text would show.
Something is wrong with flash, maybe. The problem starts when I add another textbox to the stage.
I do not want to upgrade to a newer flash, but I could if I have to.
If anybody knows how to fix my problem, please tell me.
I think that embed fonts is optional if you create and add an instance of TextField trough AS3 (excepts if you specify a font that is not present on another computer).
In the example here bellow, the text for textfield1 and textfield2 is always displayed, so I probably misunderstand your question.
Best regards.
Nicolas
PS : the "var timer:Timer" and the callback function are only used to make this example switch an loop from frame 1 to frame 2
Example 1
frame 1:
import flash.utils.Timer;
import flash.events.TimerEvent;
if (! textfield1 && ! textfield2)
{
import flash.text.TextField;
import flash.geom.Point;
var textfield1:TextField = new TextField();
var textfield2:TextField = new TextField();
var tfPosition:Point = new Point(100,50);
}
try{
removeChild(textfield2);
}catch(e:Error){
(trace (" ERROR : textfield2 is not already added"));
}
addChild(textfield1);
textfield1.x = tfPosition.x;
textfield1.y = tfPosition.y;
textfield1.text = "hello";
stop();
function playStop(te:TimerEvent):void{
play();
}
if(!timer){
var timer:Timer=new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,playStop);
timer.start();
}
frame 2 :
removeChild(textfield1);
addChild(textfield2);
textfield2.x = tfPosition.x;
textfield2.y = tfPosition.y;
textfield2.text="goodbye";
stop();
Example 2
If you have two instances of a TextField manually placed on the Timeline, that you select "use device fonts" and the names for the instances are really called "textfield1" on the first frame and "textfield2" on the second frame.
(I've done it by copy and paste in place and didn't get any issue neither).
This works on CS6 too... The text is well displayed
So give us more details please.
Instance of TextField on frame 1 named "textfield1"
code on frame 1 :
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextField;
textfield1.text = "hello";
stop();
function playStop(te:TimerEvent):void {
play();
}
if (! timer)
{
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,playStop);
timer.start();
}
Instance of TextField on frame 2 named "textfield2"
code on frame 2 :
textfield2.text="goodbye";
stop();

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?

compiler errors when loading in XML data into flash

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.

AS3 Loader keeps reloading same swf over and over

I have a flash animation made on the main timeline of the SWF with a couple of layers, some functions and some keyframe labels. For example, i have a movieclip of a star that come across the screen and then triggers a dispatchEvent for the main timeline to go to frame label "next".
Here is a sample of the actionscript used on the main timeline :
Stars.addEventListener("fadeInTitle",_fadeInTitle);
function _fadeInTitle(e:Event):void {
Title.gotoAndPlay("fadeIn");
Stars.removeEventListener("fadeInTitle",_fadeInTitle);
}
stop();
That SWF alone works perfectly. Problem comes when I try to load this SWF into another one.
What happens is the loader keeps reloading the SWF over and over, overlapping them and the actionscript that's on the main timeline of the loaded SWF is ignored, the timeline plays continuously. Here is the code i use to load the SWF :
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("Fly.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event){
addChild(loadEvent.target.content);
}
function onProgressHandler(mProgress:ProgressEvent){
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}
startLoad();
There's nothing special there. Just a simple loader.
I have found a workaround by putting the entire animation inside one main movieclip and put that movieclip on the main timeline (one keyframe, one layer, no actionscript) and then load it. That way it works fine but it feel more like a patch than a solution. I would really like to know why it's bugging when you try to load an external SWF that use the main timeline with multiple layers, keyframes and actionscript.
Any help/hint will be greatly appreciated.
Thanks a lot for reading.
m
First take the loader instantiation out of a function, it is not necessary. Second, kill your listeners in the onComplete function. Third, if this loader code is on the timeline of your loader shell, make sure that there is not more than one frame, or if there is (not sure why there would be though) place a stop on the frame containing the loader code. Or even better, use a Document class to contain your loader code rather than putting it on the timeline. My best guess is you were calling startLoad() over again somehow. Also, make sure you have the flash debug player installed so you are getting proper error reporting when viewing this in a browser.
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("Fly.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
function onCompleteHandler(loadEvent:Event)
{
mLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler);
addChild(loadEvent.target.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}