Flash var Loader issue - animation changing - actionscript-3

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.

Related

Assigning externally loaded image to movieclip

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);

As3 change object width/height, then set new size scale as 1

I have an object manipulation function that(right now) manipulates the scale of the objects inside of an array to give real-time size changes in relation with each other.
What I would like to know is if there's a way to change an object's width/height(to fit the screen size since it's a mobile app) and then reset the scale so that the new width/height has a scaleX/scaleY value of 1.
The width/height are properties that directly influence the scale of a DisplayObject. You cannot resize it without affecting the scale.
You can however:
Draw the image as bitmap
Redraw it if it's a primitive
Put it in a holder
A little about every solution:
Drawing a DisplayObject (or any IBitmapDrawable) is done through creating a BitmapData and using a draw() call. The up-side is that it will be a bitmap and thus save some rendering time. The downside is that if it's a large image it will take memory (can be critical for mobile) and it won't have interactivity/animation unless you make a script that would read the animation.
If you're drawing the element though the Graphics class's API, you might just make something like a resize() method that you would call on window resize/flip-orientation. Just utilise the clear() method of the Graphics object and redraw the whole thing.
Lastly, probably your best pick. Resize your object. Make a new Sprite (I choose Sprite because it's interactive and you probably want that) and add the resized object to that newly made sprite while the Sprite is just added to the display list like you added the resized object before. If it's hard to understand, here's some code:
myResizeableObject.width = newWidth;
myResizeableObject.scaleY = newScaleY;
var holderSprite:Sprite = new Sprite();
myResizeableObject.parent.addChild(holderSprite); // if you don't have a specific place to add the myResizeableObject, don't use myResizeableObject.parent - it's ugly
holderSprite.addChild(myResizeableObject);
Hope that helps you!

ActionScript3: How to make an animation out of a series of images?

I'm new to AS3 and I'm trying to create a simple game with it.
So far, I have been able to draw images like this:
[Embed(source = 'C:/mypath/myimage.png')]
public static var myImageClass:Class;
private var myImage:Bitmap = new myImageClass();
and then render myImage.
but that draws only a picture with no animation.
What I want is to import this picture:
and then cut the image to series of subimages and draw an animation out of them, rather than a single image. How may I do this?
Thanks!
This is called "Blitting". You could accomplish it with fairly decent results, depending on your deployment target and how many animations you require, using BitmapData.copyPixels(), but it's more ideal to use the Starling Framework, which employs Stage3D hardware acceleration.
More here:
Introducing the Starling Framework (Video tutorial)
Starling documentation
What you are looking for is SpriteSheet support. You can easily write this yourself or use existing libraries (like Starling for instance).
The idea is to draw an area of the image at each frame to actually create the animation. Depending on the format of your sprite sheet, you may have to add another file to describe the positions of each rectangle to draw.
This page explains how to implement it.

as3 crop image loaded as MC

Hi this kills me :) I am using senocular for as3 move,rotate,scale,skew loaded image into MC and works great, but spent a lot of time, can't find nice solution for cropping such MC (with loaded image) with mouse. Do someone have solution (code) for this?
To display the cropped area, all you need to do is apply a mask, which is just another Display Object.
I haven't used Senocular's code for this, but if you make the mask the target of his move / scale code, then you can easily implement cropping. There's plenty on masking in the Adobe docs: http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_28.html
In practice, you have to hide the resize / move controls when cropping, and vice-versa, which is why tools like Flash itself, or Photoshop, have separate transform and crop modes.
From Senocular's docs:
// import for the Transform Tool classes used
import com.senocular.display.transform.*;
// create a box object to interact with
var box:Sprite = new Sprite();
addChild(box);
box.graphics.beginFill(0xAACCDD);
box.graphics.drawRect(-50, -50, 100, 100);
box.x = 100;
box.y = 100;
// create the Transform Tool
var tool:TransformTool = new TransformTool(new ControlSetStandard());
addChild(tool);
// select the box with the transform tool when clicked.
// deselect when clicking on the stage
box.addEventListener(MouseEvent.MOUSE_DOWN, tool.select);
stage.addEventListener(MouseEvent.MOUSE_DOWN, tool.deselect);
Just do this, but box needs to be the mask of your movie clip, so that when you resize it, you will crop the movie clip.

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.