Assigning externally loaded image to movieclip - actionscript-3

I have existing "replay_btn" movie clip. Initially, on stage it is blank. In as3 code, I'm loading an external image using xml.
Like this,
var replaySlideImage:Loader = new Loader();
replaySlideImage.y = 561;
replaySlideImage.load(new URLRequest(xmlPath.replayButton.icon));
addChild(replaySlideImage);
Now, when I run the swf file, the loaded image goes on top of the replay_btn move clip. I want to know,
how do I make the "replay_btn" tell that the loaded image is your background image.

Use addChildAt() rather than addChild() to assign a DisplayObject's index when adding it to the stage.
addChildAt(replaySlideImage, 0);

Related

Flash var Loader issue - animation changing

So, I've use a loader action script for a few banners I've been working on, and usually things go relatively smoothly (for Flash). However, the animation changes once I guide the image to the code. Has this happened to any one else? Below is the code I am using:
var imageLoader:Loader = new Loader();
var image:URLRequest = new URLRequest("http://972b6ac7e316515e1890-2848ccf658e0edc35f614dd3380d9fcb.r27.cf2.rackcdn.com/Background_othersizes.png");
imageLoader.load(image);
addChild (imageLoader);
I assume you have created animation in the Flash IDE with static image (linked from the library), and now you try to add image in runtime. Loading of the image is asynchronous process, so I would recommend account it in your animation and logic.
Also place in your MovieClip where image will be loaded, transparent shape as a background, of the same size as image, so environment will be aware of display object size, and all your transformations over MovieClip will be accounted accordingly. Also check placement and scaling of the image.

parent.AddChild not working after protecting swf using SWFProtection!

I usually, use SWF Protection, to protect my swf's from decompiling.
It also adds a load bar to the swf.
The problem is that I have codes like this:
logo= new marca();
parent.addChild(logo);
logo.mouseEnabled=false;
I use parent, because I need to put the movie clip above everything, because my application allows the user to add a lot of things to the stage, so a don't want anything covering the logo.
The application works well while unprotected, but If I protect it using SWF Protection, then, I get just white screen. Nothing appears after loading.
Is there another way, to put a movieclip above everything, without being necessery to add a ON ENTER FRAME LISTENER, to update the movieclip deph, to keep it above everything?
You can use addChildAt instead of addChild to add your other clips to the stage under the logo's level.
var levelUnderLogo:uint = numChildren == 1 ? 0 : numChildren-2;
clipYouWantUnderTheLogo = new MovieClip();
addChildAt(clipYouWantUnderTheLogo, levelUnderLogo);
edit: You can also put every other clip inside another clip that is always under the logo.
var base = new MovieClip();
addChild(base);
var logo = new Logo();
addChild(logo);
// Add all your other objects into the "base" clip.
var someClipUnderTheLogo = new MovieClip();
base.addChild(someClipUnderTheLogo);
You are getting the white screen because the swf embed method is breaking in the javascript. Basically you have a javascript error.
Because you did not post code I can't help you much more. All I can say is put alerts in the javascript and see how far you get.

Transfer a BitmapData object from an AS2 swf to a parent AS3 swf via SWFBridge

I need to transfer a BitmapData object created in an AS2 swf to an AS3 swf. I'm using gskinner's SWFBridge to establish a two way communication between both flash movies.
The AS3 movie loads the AS2 swf which works completely standalone and lets the user manipulate MovieClips and finally generate an image from the composition he creates. I need the AS3 movie to receive this image (bitmapData), do some fancy image processing stuff AS2 isn't able to do and send the new image back to the AS2 movie.
So here's the code
AS2 swf:
var userCompo_mc:MovieClip = container.createEmptyMovieClip("userCompo_mc",10);
var image:BitmapData = new BitmapData(userCompo_mc._width, userCompo_mc._height);
finalCompo.attachBitmap(image); // Just to make sure the final bitmap is right
image.draw(userCompo_mc, compo.title);
//Send the image to the AS3 movie
sb1.send("imageTransfer",image);
AS3 swf:
function imageTransfer(bitmapData:BitmapData, title:String):void
{
var bmp:Bitmap = new Bitmap(bitmapData);
this.addChild(bmp);
trace(title); // --> returns the right title
trace(bitmapData); // --> returns null
}
I think using something like copyPixel32(), saving everything into an array and then passing it to AS3 would do the trick but it's really a performance hog.
Also, I'm not allowed to convert the AS2 swf into AS3 code.
Any suggestions?
Thanks you!
It seems like the as2 movie adds some decorations/movieclips to a an image.
After that you draw it and send attempt to send it to as3.
Since looping though all the pixels is slow, as you mention, I imagine it's faster to draw the as2 content from the as3 movie.
e.g.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
loader.load(new URLRequest('yourAS2Movie.swf'),new LoaderContext(true));
function loaded(event:Event):void{
var as2Clip:AVM1Movie = AVM1Movie(loader.content);
var bd:BitmapData = new BitmapData(as2Clip.width,as2Clip.height,false,0);
bd.draw(as2Clip);
addChild(new Bitmap(bd));
}
In this snippet the as2 content is drawn on load. In your case you would trigger/call a function that draws the as2 content via SWFBridge, after the as2 movie is ready/setup for what you need.
This works assuming you want to display the as2 content inside the as3 movie, which means you will load the as2 movie anyway. If not, either you load the as2 content, but don't add it to the display list, which means you'll be loading the as2 movie. Otherwise, you could try to save your final bitmap from the as2 movie using a server side language(like php for example), then trigger a function in the as3 movie, via SWFBridge, that will load the previously saved image.
HTH

AS3 ScrollPane dispatch event to content

i've loaded external swf into ScrollPane and i need to dispatch click event to this external swf. is it possible? ScrollPane.content.dispatchEvent(new MouseEvent(MouseEvent.CLICK,true)); doesn't work. this is obvious cuz ScrollPane.content is an DisplayObject and it have not CLICK event...
I can't use MovieClip as container for external swf cuz external swf is a documents converted to swfs using openoffice and it doesn't want to load inside MovieClip but perfectly loads inside ScrollPane and react on mouse clicks,but i need to simulate mouse click on it.
so you're saying that the following won't work or you haven't tried it?
var exSWF:MovieClip = MovieClip( ScrollPane.content );
or
var exSWF:Sprite = Sprite( ScrollPane.content );
Not sure to understand what you mean when you say that your external SWF won't load into a MovieClip.
Do you know what version of Actionscript was used for the external SWF, you can check that in debug mode by looking at the properties of the ScrollPane.content?

Make mask visible in ActionScript 3.0

I have Loader object containing loaded swf. I don't know how the shape of this swf looks like - it's not necessarily rectangular.
I want to add some light reflection on it. I need to mask this reflection with Loader, but in the same time I need this Loader to be visible.
I don't want to load swf twice, because it may contain some dynamic, script-generated content, which can produce different results in each Loader.
And that's quite a problem, isn't it? Any ideas?
Image: http://www.freeimagehosting.net/uploads/12e6b9cd63.jpg
you could add your instance of the loaded swf to the stage, and for the reflection use he same movieclip/sprite and draw it to a new BitmapData. do the transformations needed and then add to stage.
Or imagine the following situation, instead of having the swf that is loaded adding it's own graphics to library you could do this from the loading application, so for instance, give the instance name of MyDisplayObject to the movieclip in the loaded swf and export to actionscript. After you load the swf you could use the following code to access the library, so you can add this object number of times you need, in you case 2.
here is the code (from adobe live docs)
function initHandler(e:Event) {
var applicationDomain:ApplicationDomain = e.target.applicationDomain; // e.target is the loaderInfo object
var testClip:Class=applicationDomain.getDefinition("testClip") as Class;
var clip = new testClip();
addChild(clip);
var reflection = new testClip();
addChild(reflection);
reflection.y= 100;
}
Hope this get's you on the right track.