views:

93

answers:

3

i'm trying to embed a swf to my as3 flex project like this:

[Embed(source = "../assets/next_button.swf")]
[Bindable]
protected var nextButtonClass:Class;
protected var next_btn:MovieClip = next_btn = new nextButtonClass() as MovieClip;
// ...
next_btn.addEventListener(MouseEvent.CLICK, onAdChange);

next_button.swf is as2 and created with adobe flash cs4. there is a single button inside it.

if i change type of button symbol to movieclip at next_button.fla, there is no problem at passing CLICK event.

i tried to cast next_btn to mx.controls.Button and fl.controls.Button classes, next_btn is becoming null in that case.

by the way button is reacting mouseover and click events properly just doesn't pass it to upper swf.

is there any trick i can do to pass Button events to my container swf?

A: 

I don't think it is possible for an As3 script to access properties of an AS2 SWF. If you have access to the fla, why not change the button fla into an AS3 project?

PatrickS
actually i have to write both as2 and as3 version of the same project. i wanted to be able to use same assets for both project.and assets will be prepared by a designer group, we may not have a cs4 under our hand to change flas.and as you say there is no problem if assets are as3, and i'm afraid there is no solution for as2 buttons.
ekesken
PatrickS
that's how we seperate it :) our designer team has no idea about flex, mxml etc. they're binary guys.
ekesken
A: 

Try embedding and instancing the symbol from inside the swf, not the entire swf:

 [Embed(source = "../assets/next_button.swf", symbol"MyButton")]

You will obviously need to replace MyButton with the actual symbol name of the button.

That should give you more direct access to it, since it won't be wrapped by a Loader.

grapefrukt
i gave button name 'next_btn' and changed code so: [Embed(source = "../assets/next_button_as3.swf", symbol = "next_btn")]i got these errors:Error: definition for symbol 'next_btn' not foundError: Unable to transcode ../assets/next_button.swf.but i got same errors when i tried it with next_button_as3.swf, am i doing something wrong?i can trace this.next_btn inside both swfs, outputs are so:as2 => _level0.next_btnas3 => [object next_button]
ekesken
you need to set a "linkage id", not an instance name. http://www.jessewarden.com/archives/flex/preloader/flash_preloader_03.gif
grapefrukt
thanks, i tried so, no error at compile time. but "var next_btn:MovieClip = new nextButtonClass() as MovieClip;" code assigns null value to next_btn variable this time. how can a "new" operator return null value?
ekesken
if the cast to `MovieClip` fails it'll be null, try assigning it to a `Sprite` instead
grapefrukt
and that's the solution! but Sprite didn't work, used DisplayObject instead.
ekesken
A: 

to summarize, after the solution grapefrukt suggested, code looks like this:

[Embed(source = "../assets/next_button.swf", symbol="next_button")]
[Bindable]
protected var nextButtonClass:Class;
protected var next_btn:DisplayObject = new nextButtonClass() as DisplayObject;
// ...
next_btn.addEventListener(MouseEvent.CLICK, onAdChange);
ekesken