Duplicate image with Haxe - actionscript-3

My goal is to make a wide map using only one square image.
Using actionscript 3 the solution is to simply make new Bitmap from the Loader:
var loader:Loader = new Loader();
loader.load(new URLRequest("xyz.png"));
this.addChild(loader);
var duplicationBitmap:Bitmap = new Bitmap(Bitmap(loader.content).bitmapData);
Unluckily, Haxe API doesn't allow to do that. I can't get bitmapData from loader content…
Anyone has a clue? Thanks.

The API is the very same, so I guess the problem is how you are trying to cast; try using:
var duplicationBitmap= new Bitmap(cast(loader.content, Bitmap).bitmapData);

What you mean the API doesn't allow it? By looking at these:
http://haxe.org/api/flash9/display/loader
http://haxe.org/api/flash9/display/bitmap
It seems you should be able to port that code?
Are you getting any compiler error?
J

That's really weird, Bitmap is coming from the playerglobal.swc and shouldn't be related to any Haxe specific "API". Aren't you just attempting to access loader.content whilst the content is not yet loaded (i.e. the example above).

Related

easiest way to add a swf animation in a flash builder project

I have a very simple flash aimation (frame based) thatI just have to run once. What is the quickest and easiest way to embed this into flash builder 4.6.
I have tried about 5 or 6 different ways but cannot seem to get it, mainly due to type mismatch and even with casting it di not work.
I tied the embed metatab but should I be using the loader() class?
Try this:
[Embed(source="movie.swf", mimeType="application/octet-stream")]
const movieClass:Class;
var loader:Loader = new Loader();
loader.loadBytes(new movieClass() as ByteArray);
addChild(loader);

Starling - load SWF image(vector) into a Image

I'm trying to convert an old project of mine to use Starling for some extra performance.
I've come to a problem when I'm loading my SWFs and trying to display them.
Here is the code I used before: (no Starling)
private function swfLoaded(e:LoaderEvent):void {
var spr:Sprite = new Sprite();
spr = e.currentTarget.content;
bitmapData.draw(spr ...);
}
The problem when I'm using Starling is that the currentTarget.content is a flash.display.displayObject.
cannot convert com.greensock.loading.display::ContentDisplay#90ffec1 to starling.display.Sprite
I want to find a way to "convert" the flash.display.displayObject into a starling Sprite.
I also want to be able to store the loaded swfs content into a array as a sprite.
Thanks in advance,
Tompa
You're overwriting spr with a different value immediately after you create it, for one thing.
After you do the bitmapData.draw() call:
var tex:Texture = Texture.fromBitmapData(bitmapData, false, false);
The new texture can then be used to create a Starling Image sprite.

unload dynamically loaded swf after displaying it AS3

I am doing a presentation on which I need to use a lot of video clips. I load all these videos dynamically using Loader. I use a code snippet like this:
var req:URLRequest = new URLRequest("video.swf");
var a:Loader = new Loader();
a.load(req);
stage.addChild(a);
a
Now the issue is: When I get to say the 7th one, it starts lagging. I do not know why, but I think it is because everything is loaded to memory. Is there a way I can erase a video from memory after displaying it? Or is there another solution to this?
If you just load a new video each time and add it to the stage, you will have a rather big hierarchy of movies sitting on top of each other; all kept on stage and in memory.
If you keep a reference to the previously loaded movie, you can just remove it from the stage when the 'next' movie is loaded. Haven't tested this properly, but just to give you an idea of what the code might look like:
var oldLoader:Loader = null;
var a:Loader = new Loader();
a.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
a.load(<your url>);
function loader_complete(e:Event):void {
var newLoader:Loader = e.currentTarget.loader as Loader;
stage.addChild(newLoader);
if(oldLoader != null) {
stage.removeChild(oldLoader);
oldLoader = null;
}
oldLoader = newLoader;
}
I think I found the solution. If you use removeChild, it only stops displaying, but the whole thing is still in memory (cache). So the more you load the videos, the more you fill up the cache. What we need is something that completely clears the cache before loading another video.
I used unloadAndStop() and it seem to have completely done the trick, unless someone has something against it.
Thanks again

How do I include flashvars in AS3?

I am brand new to AS3 and I am trying to move all of the data from an html file, into a swf.
The old html file contained this coding:
<EMBED src="https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf" WIDTH="640" HEIGHT="528" FlashVars="_tunervar_shost=www.pandora.com">
So far from what I have learned I can use the loader, to substitute for the src. So in my swf, I have
var myLoader:Loader = new Loader();
addChild(myLoader);
var url:URLRequest = new URLRequest("https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf");
myLoader.load(url);
What I can't figure out though, is how to change the FlashVars from html into AS3. I have done a bit of research and from what it sounds like, I have to use something called root. I am completely lost on how to use this, and I am not even sure if this is the correct way to script it. Can someone help explain this to me?
One other problem I am having, is for some reason, the swf I am loading is blurry. Is there any way to fix this?
Try appending them to the asset that you're loading:
var url:URLRequest = new URLRequest("https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf?_tunervar_shost=www.pandora.com");

Trouble using Loader, can't access properties of loaded swf

May not have asked question correctly so I’m asking again. I’m using Flash AS3 with code in actions layer.
Main movieclip onstage is : design_mc. Within it is a movieclip already in place onstage with an instance name clipart_mc.
Now I’m also loading a ListBox to the stage and each time a selection is made from listbox myLoader9 is used to load selected .swf into design_mc.clipArt_mc.
Now within each of the .swf files loaded into design_mc.clipArt_mc there is a mc I’d like to color transform called color_mc.
So now the listbox is onstage and I make a selection that places heart.swf inside of design_mc.clipArt_mc. I want to access heart.swf so I did this:
var child:DisplayObject = myLoader9.content.contentLoaderInfo.content.color_mc;
var colorTrans3:ColorTransform = new ColorTransform();
var trans3:Transform = new Transform(child);
I still can not get to heart.swf. Can anyone help please?
Anne
I'm working with Embedded SWFs here, but I think it's the same. I can get my MovieClip from the Loader "content" property. Like this:
var myMC:MovieClip = MovieClip(myLoader9.content);
Try this way, instead of using "content.contentLoaderInfo.content".
:)
I got it. I gave the loader a name:
myLoader9.name = "currentClip";
Then I can target in main movie using:
var child:DisplayObject = MovieClip(parent).design_mc.clipArt_mc.getChildByName("currentClip").content.color_mc;