AS linked library items with TextFields does not works - actionscript-3

I try to use graphics resources(MovieClips, etc) from another SWF.
I have a *.fla file, which has AS3 linked movie clip "GameInterface". Then I publish it as res.swf.
And in my AS3 project I'm using this code to add this MovieClip:
public function Main() {
var myLoader:Loader = new Loader();
var myUrlReq:URLRequest = new URLRequest("res.swf");
myLoader.load(myUrlReq);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
}
private function onLoaded(e: Event): void{
var test:Class = e.target.applicationDomain.getDefinition("GameInterface") as Class;
var testMC:MovieClip = new test() as MovieClip;
addChild(testMC);
}
And it works fine, if there is no any TextFields in my GameInterface movie clip.
But if I have a TextField in GameInterface, it raises error:
[Fault] exception, information=ReferenceError: Error #1065: Variable GameInterface is not defined.
So what am I doing wrong? How can I import MovieClips with TextFields, to use it in my project?

My bad. I used TLF Text instead Classic Text. With Classic Text it works fine.

Related

as3 error: access of possibaly undefind property through a reference with static type flash.display:DisplayObject

I have this as3 project, and in frame one of the timeline I tried to load a swf movie named "menu" and in this loaded movie I have an instance of a button named "button1", and I want to add a new EventListener to this "button1". my code is here:
var theLoader:Loader = new Loader();
var address:URLRequest = new URLRequest("menu.swf");
theLoader.load(address);
theLoader.contentLoaderInfo.addEventListener(Event.COMPLETE , swfDidLoad);
function swfDidLoad(evt:Event){
if(theLoader.content){
addChild(theLoader);
var button:SimpleButton = theLoader.content.button1;
button.addEventListener(MouseEvent.CLICK, handler1);
}
}
function handler1 (event:MouseEvent):void
{
removeChild(theLoader);
gotoAndStop(10);
};
but I get this undefind property error. what should I do? Am i doing this right at all?
The reason you are getting that error is because you are trying to access button1 on theLoader.content which is a non-dynamic DisplayObject (this means that only explicitly defined properties/methods are valid). You must first cast it to a MovieClip (which is dynamic).
You should change that line to:
var button:SimpleButton = MovieClip(theLoader.content).button1;

How to loop SWF file loaded with Loader?

I want to loop a swf file that has been loaded with via the Loader class in AS3.
My code looks as following:
public class MyLoader extends MovieClip {
public function MyLoader() {
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("external-movie.swf");
myLoader.load(url);
myLoader.contentLoaderInfo.addEventListener("complete", function() {
});
addChild(myLoader);
}
}
From what I understand the Loader has no event for when the embedded movie is finished? Is there a way to figure that out? It must not be a AS3 implementation. I just want a movie that has been exported from Indesign to run in a loop. Thanks in advance
Especially when you have little experience programming you should avoid dirty shortcuts as they'll only get you a lot of trouble. So avoid anonymous function and avoid using string in place of static event variables.
This being said, if your loaded movie has its own timeline then it will be converted into a MovieClip. Also that movie is not embedded but loaded and that's a big difference.
Keep a reference of that movie and the loader:
private var theLoadedMovie:MovieClip;
private var myLoader:Loader;
Listen for the INIT event instead of the COMPLETE event (movies with timeline start to play when their first frame is loaded "INIT", the COMPLETE event fires when the whole movie is loaded).
myLoader = new Loader();
var url:URLRequest = new URLRequest("external-movie.swf");
myLoader.load(url);
myLoader.contentLoaderInfo.addEventListener(Event.INIT, handleInit);
In your handleInit method keep a reference of that movie:
theLoadedMovie = myLoader.content as MovieClip;
addChild(theLoadedMovie);
theLoadedMovie.addEventListener(Event.ENTERFRAME, handleEnterFrame);
in your handleEnterFrame method check the movie progress to know when it has ended:
if(theLoadedMovie.currentFrame == theLoadedMovie.totalFrames)
{
//movie has reached then end
}

AS3-embedded SWF comes up as null

So I have a SWF embedded in my AS3 project, but when I try to do anything with it, it says it's null.
The code looks like this:
[Embed(source = "../lib/Introduction.swf", mimeType = "application/octet-stream")]
public var introClass:Class;
(after a bunch of irrelevant stuff...)
var intro:MovieClip = new introClass() as MovieClip;
intro.play();
(The error message it gives me is a standard #1009 error.)
I've tried a bunch of stuff including using Loaders, not using MovieClip, etc, but at best, only the audio (not the video) of the SWF loads up, and at worst, the entire application crashes when the SWF tries to load. How do I get the SWF to be recognized?
(I'm using FlashDevelop if that helps.)
You can do this:
[Embed(source="asset.swf", symbol="symbol")]
private var symbolClass:Class;
var symbol:MovieClip = new symbolClass();
If you want to embed a symbol from an art SWF.
Instead if you want to import animations this is the solution:
[Embed(source="/loading.swf", mimeType="application/octet-stream")]
public var LoadingAnimation : Class;
// allows us to import SWFs to use as animations
var context : LoaderContext = new LoaderContext (false,
ApplicationDomain.currentDomain);
context.allowCodeImport = true;
var loader : Loader = new Loader ();
loader.loadBytes (new LoadingAnimation (), context);

Embed bitmap in ActionScript3

How can I embed a bitmap in Actionscript 3 and get the BitmapData?
public class MyGame extends Sprite {
[EMBED(source="Assets/helicopter1.png")] private static var BMClass:Class;
public function MyGame() {
var BM:Bitmap = new BMClass();
var BMData:BitmapData = new BitmapData(BM.width, BM.height);
BMData.draw(BM)
}
}
I've tried everything. If I ever try to instantiate the embedded class (new BMClass();) I get this error:
TypeError: Error #1007: Instantiation attempted on a non-constructor..
If I use
[EMBED(source="Assets/helicopter1.png")] private static var BMClass:BitmapData;
or something similar the BitmapData is null.
Edit:
So I figured out that the embedded data is null, but I can't figure out why. What did I do wrong in the embedding?
Looks like you are embedding correctly if you don't get an error transcoding. You should be able to get the bitmapData directly from the bitmap:
[Embed(source="picture.jpg")]
private var Picture:Class;
// create a bitmap of the embedded
var pic:Bitmap = new Picture();
// add to display list
addChild(pic);
// if you need to get the bitmapData for something else
var bitmapData:BitmapData = pic.bitmapData;
You don't need to instantiate as BitmapData and draw - you can simply:
[Embed(source="Assets/helicopter1.png")]
private var AssetClass:Class;
var bitmap:Bitmap = new AssetClass();
In some editors (at least my version of Intellij) the Embed tag is case sensitive. I got the exact same error you have when using [EMBED] but it worked great when I switched to [Embed]

Getting BitmapData from Embedded class

[ Embed('Assests/ui/Main.swf', symbol='backgroundImage')]
private var background01:Class;
private function getBitmapData(className:String):BitmapData
{
var mc:MovieClip = (new background01) as MovieClip;
if (mc == null) throw new Error('mc is null');
var myBitmapData:BitmapData = new BitmapData(mc.width , mc.height);
myBitmapData.draw(mc)
return myBitmapData;
}
Hi there. I'm having a problem working this out. I want to return bitmapData from a symbol that is embedded in a flash swf file. background01 is the class name exported to as3 in the flash swf file. As you can see from above I'm finding the swf with no problem. and I'm pullin the data back from the swf file with no prob. I can type addChild(new background01) and the image will show up. But when I've tried to cast to a bitmap , bitmapasset and movieclip. It always returns null. I want to get access to the bitmapdata of this image/movieclip. It should be returning a vertex circle drawn in flash and created to be a movieclip symbol. So what I would expect to be returned would be a MovieClip.
Has anyone ever done this, and if so, could you provided some sample code..
Thanks
LinX
Try:
var mc:MovieClip = (new background01()) as MovieClip;
instead of
var mc:MovieClip = (new background01) as MovieClip;