easiest way to add a swf animation in a flash builder project - actionscript-3

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

Related

How do I build a movie clip in Actionscript 3

How do I create the AS3 equivalent of a moviescript with multiple frames?
If I were using the Flash IDE, I would put whatever stuff I wanted on frame 1, other stuff on frame 2, etc. and step through the frames as the user clicks the "Next" button. Or perhaps put in keyframes and tweens and let the system play through the frames at a fixed rate.
I don't see a way to do this in AS3, even though all the descriptions I've seen say that Flash CS3 turns your timeline and frames into ActionScript, and I would like to know how to do the same without having the Flash IDE (e.g., working in Flex).
Let's take a simple example: I have 3 frames. Frame 1 contains the splash page (a lot of text and a button). Frame 2 contains one image, one label, and one button that says "Next". Frame 3 contains two images and one label.
How would you build that in AS3?
Flash CS
You will put your logic code in key frame, and do something with the text,button etc. It's hard for multi uses to edit and work on it.
AS3 use IDE like Flash Builder
Flash CS will is just used to make animation swf
Assume we have a swf named A.swf
A.swf
mySymbol (have a link name like com.mySymbol)
subSymbol1(named subSymbol1)
nameLabel(named label1)
addressLabel(named label2)
subSymbol2(named subSymbol2)
nameLabel(named label1)
addressLabel(named label2)
Here is how you use A.swf in flash builder
Class MyView {
public function MyView() {
var loader:Loader = new Loader();
var url:String = "A.swf";
var urlReq:URLRequest = new URLRequest(url);
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(urlReq, loaderContext);
}
private function onLoadComplete(e:Event):void {
//now you can get defined symbols in A.swf
var c:Class = getDefinitionByName(" com.mySymbol");
//get a mySymbol instance
var mc:MovieClip = new c();
//add to parent
some.addChild(mc);
/*what you said you got three frames,
Just like set like subSymbol1 and subSymbol2 in this A.swf
add some text in subSymbol1 and other in subSymbol2 */
mc.subSymbol1.visible = false;
mc.subSymbol2.visible = true;
}
}
It could make the program and view indenpendent in a way.
You would most likely just create each of those frames as an individual Sprite.
When you want to switch between them, you'd use removeChild() to hide the old one and addChild() to show the new one.
If you want to get fancy you can add Tweens (either built-in or from a tweening engine). This would allow you to fade between the frames, or scale them in, or slide from left to right, or whatever.
If you need to do more complex sequenced animations you can look into something like TimelineLite to help with that.

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.

Sound not being played

var sound:Sound = new Sound(new URLRequest("Phone.wav"))
sound.play(0, 20);
Why does sound not play? There are no errors.
Flash doesn't support loading external WAV files with the Sound class, only MP3s. I don't know why it isn't giving any errors but I haven't used the Sound class much myself so it might be normal.
There are three solutions for this. First of all, WAVs are supported if you import them into the library as Sound objects. This is probably the best choice if you're using the Flash IDE.
If you're not using the IDE, you may be able to embed the file instead using Flex's [Embed] tag, if you're compiling it using the Flex SDK.
Otherwise, can either convert your sound to an MP3 file and load it as usual:
var sound:Sound = new Sound(new URLRequest("Phone.mp3"));
sound.play(0, 20);
Or, if you prefer to use a WAV, you can use the as3wavsound library. Here's a tutorial outlining how to use it.
Hope that helps!
You need to use a SoundChannel try this.
var soundChann:SoundChannel;
var sound:Sound = new Sound(new URLRequest("Phone.wav"))
soundChann = sound.play();

ActionScript 3.0 : Display images at every 10 seconds while music is playing

I want to Display images at every 10 seconds while music is playing in Action Script 3.0.
I am very new to As3 . I have started to learn As3.But I need to do this in very quick time.I dont know what is the starting point for acheiving this.please give me some suggestions to do this.
var timer:Timer = new Timer(10000);
timer.addEventListener(TimerEvent.TIMER, timerAction);
timer.start();
function timerAction(e:TimerEvent):void
{
// do your actions here
}
and refer the link for help.
http://www.republicofcode.com/tutorials/flash/as3slideshow/4.php
I suppose, that's what you need.
Also, for loading bitmaps, take a look at Loader class. That's how it works:
var loader:Loader=new Loader();
loader.load(new URLRequest(/*Here goes path, including extension, for example */"image.gif"));
addChild(loader); // After that you can treat `loader` just like any visible object

Duplicate image with Haxe

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