PDA

View Full Version : Inherit/extend library symbol



kleelof
August 26th, 2008, 04:54 AM
Hello,

Is it possible to inherit/extend a library symbol? It is possible I am using the wrong terminology, so here is a description of what I am trying to do.

I have a button in my library. This button has a TextField on it. What I want to do is create multiple buttons from this and drag them onto the stage so that I have indivudual buttons with their own messages on them. I know I can drag as many instances of a single button as I want, but they each would have the message contianed in the original. I need each button to have a unique message, but all have the same actions.

Now, I know I could make a new class that extends the SimpleButton class, but to be honest. I am a bit lazy and don't want to have to set all the button and text parameters by code.

I thought I saw somewhere once where someone used lib.[symbolName] to access a library symbol.

take care,
lee

senocular
August 26th, 2008, 09:38 AM
Now, I know I could make a new class that extends the SimpleButton class, but to be honest. I am a bit lazy and don't want to have to set all the button and text parameters by code.

How do you expect to do it then?

kleelof
August 26th, 2008, 10:28 AM
Hello,

If I make a custom class, when I create a new symbol, I can use my custom class as the base class for that symbol. And, of course, any change I make in my custom class shows up in the symbol I created.

Now, when you make a new symbol and export it, a new class name is made for it. If it exports as a class, can't you use it as a base class for other symbols?

I'm sure the end result I want to achieve has a really easy solution to it that I just dont know, but if I can do what I described above, I know I could get the results I want. And that result is a group of buttons that behave the same but each has a different text. I would like to use the Flash GUI to adjust the settings, glow, up, down etc. of one button and have it apply to them all. To set all of that through a custom class and test it over and over till I like the way it looks seems like alot of work. And, like I said before, I am feeling a bit lazy about the idea of doing that.:drink::-/

Any ideas would be greatly appreciated.

take care,
lee

Anil_kumar
August 27th, 2008, 05:47 AM
var Btn_1 = new BtnClass();
Btn_1.TextInBTN.text ="caption 1";
Btn_1.name = "Btn_1"
addChild(Btn_1);

var Btn_2 = new BtnClass();
Btn_2 .y=80;
Btn_2.TextInBTN.text ="caption 2";
Btn_2.name = "Btn_2"
addChild(Btn_2);

var Btn_3 = new BtnClass();
Btn_3 . y=160;
Btn_3.TextInBTN.text ="caption 3";
Btn_3.name = "Btn_3"
addChild(Btn_3);



BtnClass.as

package {
import flash.display.MovieClip;
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class BtnClass extends MovieClip {
public function BtnClass():void {
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK,ClickHandle r);
this.TextInBTN.mouseEnabled = false;
}
private function ClickHandler(e:MouseEvent) {
trace("you clicked on "+e.target.name);
}
}
}


Anil
anilkumarnd@gmail.com