How to use MXML mx.controls.Label in ActionScript - actionscript-3

I have one AS3 application which was developed entirely in AS3 without using single line of code in MXML. Of late I am realizing that MXML has some rich controls which are not provided in open source Apache Flex SDK. One library which is of most interest to me in mx.controls, it includes Label, DataGrid etc.
Now, I want to extend my AS3 application to call mxml compiled into swf file. I tried to import mx.controls inside my AS3 programs but it does not sense that. Please tell me if I am doing anything wrong. If I am able to import mx.controls inside as3 class it would save me a lot of time. Can I do this?
Alternatively, I am trying to write a few applications in mxml and then call (.swf) in AS3. Is it possible?
I tried Googling but all examples are pointing to using ActionScript inside MXML with [CDATA[]]. But I want the inverse. Calling MXML from ActionScript.
Please explain me at nuts and bolts level as I am struggling with this a lot.
thanks in advace

You can't do that because Flex, that uses MXML, is framework built on top of the Actionscript. But you can do reverse. In Flex MXML you can use Actioscript code, and you can also use Flash components like Sprite, MovieClip... by using UIComponent or SpriteVisualElement as their parent container.

Related

FLVPlayback without Flash CS

I'm implementing Google video Ads in flash game, using FlashDevelop. Google has a sample where they're using FLVPlayback component to display video... problem is, I don't have this class anywhere.
I've searched how to add it, but all solutions say "link to C:\Adobe\Flash CS\Components\etc" path, which obiouvsly without Flash CS I don't have... and don't want to install it just for this :)
I wonder if there is a way to get the FLVPlayback without installing Flash CS?
You can try import external adobe components swc through Flashdevelop interface.
Maybe this can help you: link
I quit and just installed the Flash Professional CC, and there linked to the component path, but it didn't work for some reason. Then I included the FLVPlayback.swf component inside my AS3 app, which compiled etc. but as I learned FLVPlayback wasn't really what I needed.
After some fumbling I made it work with Flex Spark component - VideoPlayer, used inside AS3. You can find some code on the devlist: https://developers.google.com/interactive-media-ads/community?place=msg%2Fima-sdk%2Fc3KH11vxSd0%2FeLuYneYpch4J

Anyone know a list of flash.includes? (as3)

I'm looking for a list of flash.include.whatever.whatever for as3.
If no one knows a list then can someone tell me the flash.include to use for drawing rectangle with the startFill and endFill things? Thanks for any help.
I didn't find anything on either of these googling, and the place I got the code for drawing a rectangle of course didn't have the flash.includes included in the example code... is their a reason so many people do that? Any way I can get around it?
Do you mean you want a list of the packages and classes that come with AS3? That is typically called the documentation and can be found here:
Adobe ActionScript® 3 API Reference
For drawing a Rectangle, you can start at flash.display.Shape. It has a graphics object with the methods .beginFill() and .endFill().
you can using a Graphics.
The Graphics class contains a set of methods that you can use to
create a vector shape. Display objects that support drawing include
Sprite and Shape objects. Each of these classes includes a graphics
property that is a Graphics object. The following are among those
helper functions provided for ease of use: drawRect(),
drawRoundRect(), drawCircle(), and drawEllipse(). You cannot create a
Graphics object directly from ActionScript code. If you call new
Graphics(), an exception is thrown.
The Graphics class is final; it cannot be subclassed.
here is a sample
import flash.display.*;
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(0,0,100,100);
here is a Adobe Tutorial
AS3 all display class list here
You do not necessarily need to default AS3 include. fine compile. But include only the code you can see the hint. perhaps, CS4 after that if you use a specific class will automatically include. or ctrl+space is autocompletion.
As follows by default when you install the flash is because of the SWC path.
As per I know, there is not such a thing like Flash.include. May be you're trying to ask something else or may be i am still unknown about this feature.
If you found any positive thing about this, please let me know, i want to know that new thing.

Problems implementing a Timline Editor in my level editor in Adobe AIR.

I'm currently working on an Adobe AIR project to pump out my level editor but I'm running into an issue. I basically need to implement an interactive movie editor. My question is how would you recommend I get the timeline editing started? Functionality wise it needs to be able to set tween key frames for position, scale, and alpha. Any ideas?
I've also been trying to look into pulling tween data from a swf. I'm not entirely sure how applicable this would be.
I'm not sure what you mean by movie editor - movie as in a sequence of images(bitmaps) or movie as in flash MovieClip ?
If it's the later, you could use a tweening engine like TweenLite to do the hard lifting and then it's up to you how you organize the scrollable GUI for the timeline (plenty of examples out there, starting with Flash/After Effectts/Blender/etc.) Feedback from your designer/animator is crucial I presume.
Pulling data from Flash could also be possible. If you'd like to parse the swf you can try Claus Wahlers' awesome as3swf library. Be sure to check some of his posts:
SWF Timeline Reconstruction with as3swf
Flash IDE Inspired Flex 4 Timeline Component
Another option would be to use jsfl (JavaScript scripting in the Flash IDE) and parse the tweens your designer/animator creates. It should be a matter of parsing a XML for the tween(be it old/classic or new/motion). If you go the JSFL route, you might also find the xJSFL project useful.
Also, for inspiration on game/animation tools check out Spriter

FlashBuilder: how to embed graphics for preloader?

I develop a project in FlashBuilder. The graphics and UI elements i create in the Flash IDE and give them Export Classnames. then I put the SWC in the library paths of the FlashBuilder project and create the UI elements by instanciation.
Now I want to add a Preloader for the application. I follow this article, which works:
http://pixelpaton.com/?p=4642
My question is now: I also need some graphics for the preloader. But how do I ensure that the graphics for the preloader will be loaded first, such that the preloader class can start as soon as possible?
The compiler will figure out the dependencies for your preloader class, and load them first.
For example:
public function Preloader()
{
addChild(new UIElementFromFlash());
}
Flash Builder will know UIElementFromFlash needs to be loaded before Preloader. It will also load Preloader before your main class and its dependencies as long as you have the Frame metadata tag from the article.
I'd suggest to make 2 swf files if it's possible. Make a loader.swf which loads your application swf and displays the progress and your loading animation/graphics.
See an example here: http://www.republicofcode.com/tutorials/flash/as3preloader/
Then you'll have to add URLLoader class and load your application.swf.
Try looking here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
Like Gio suggested, having two SWF files is the best practice.
However, one other solution is to use the -frame two argument of the Flex compiler. All your definitions (code and assets) will be added to the second frame of the movie, allowing your main class to listen for the loading progress of the application and display animations.
Be careful to not reference anything from the main application in your first frame, to prevent adding more weight to it.
More detail on this technique here:
http://www.andymoore.ca/2009/08/flexsdk-3-3-how-to-make-a-flash-preloader-in-as3/

Preload sound AS3

I have AS3 project, made with FlashBuilder. I'm using MovieClips from an external .SWC-file.
In a MovieClip from the .SWF-file, I want to use an audio-file.
Is it possible to preload a sound-file (e.g. .MP3) in my FlashBuilder project, and access it in a MovieClip inside the .SWC?
Thanks a lot!
Yes, I don't know hoe you create your swc's but I'll tell you my setup which always works.
I create an asset FLA which would have the mp3 among other things.
I compile using FlashDevelop, and use the preloader template. Never had problems with that.
What you can't do is use SWCs run-time.