Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flash mx 2004 symbols - buttons - as linkage

Status
Not open for further replies.

jcaulder

Programmer
Apr 22, 2002
241
US
Does anyone know how to go about creating a symbol of type 'button' and then linking that symbol to actionscript code?

Every example I can find shows how to create a 'movieclip' symbol and then linking that to actionscript code. The actionscript code for the 'movieclip' linkage looks something like:

class myClip extends MovieClip{
.
.
.
}

I would assume a symbol of type 'button' would extend a different class such as:

class myButton extends Button{
.
.
.
}

I've tried all kinds of combinations but the symbol ignores the actionscript code. It works fine with type 'movieclip' but this isn't what I need.

I am building a very extensive data driven system and would like to create button symbols such as 'cancel_btn', 'save_btn', etc. that are linked with actionscript class code. This allows me to visually use the symbol in the layout but encapsulate the logic at the class level.

Anyone know the magic formula for getting this to work? Maybe I'm just using the wrong superclass?

Thanks in advance!!
 
If I understand you correctly one way you could accomplish your goal is to create a _global function for your button actions.

Example:

On the first frame actions layer in the main timeline:

Code:
_global.myCancelBtn = function(){
   //your code here
}

Then right click on your "cancel_btn" on the stage. Select actions and add the following:

Code:
on(release){
   _global.myCancelBtn();
}

I hope that helps you. If you are trying to do something else please provide a bit more detail.


Wow JT that almost looked like you knew what you were doing!
 
That is basically what I'm trying to do but I want to have that function in a class and instantiate it across the project. Currectly, I've created actionscript files like cancel_btn.as and then included this file in the instance of the button on the form like:

#include "classes/cancel_btn.as"

The problem with this and the method you've provided is that it isn't truly object oriented. I have to manually write code on every instance of the button(i.e. 'include file' or 'on(release)'. . .) for it to access the parent methods(functions). In true OOP, the parent class would have methods and properties and as soon as it is instantiated, the child immediately inherits all of these methods and properties without having to write any code.

What I've done with the 'include' and what you're recommending with the global function are work arounds from being able to use full OOP.

Broken down into its simplest form, Flash MX 2004 is shipped with various components such as Button, TextInput, DataGrid, etc. If I want to extend one of these components in actionscript, how do I go about doing it?

With a MovieClip, it works and looks like this:

class myMovieClip extends MovieClip{
//constructor method
public function myMovieClip(){
}
//other methods as needed
}

How do I do the same do extend the 'Button' class?

class myButton extends Button{
//constructor method
public function myButton(){
}
//other methods
}

What I've just typed would seem correct but it doesn't work.

Hope I haven't made this more confusing than it needs to be. Thanks for the reply!

 
I can not find that the button class is extendable. But you should be able to create your own class and then extend that if needed.

(example from flash help (MX Pro 2004))
Code:
import mx.core.UIObject;

  class myPackage.MyComponent extends UIObject {
  static var symbolName:String = "MyComponent";
  static var symbolOwner:Object = Object(myPackage.MyComponent);
  var className:String = "MyComponent";
  #include "../core/ComponentVersion.as"
  function MyComponent() {
  }
  function init(Void):Void {
    super.init();
  }
  function size(Void):Void {
    super.size();
  }
}

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
You can't extend Button or TextField, only MovieClip. MovieClip is the base of all things visual in Flash. Don't be afraid to extend MovieClip to make your Button Classes.

class MyButton extends MovieClip

try not to think of MovieClip as being a "movie". MovieClip just means "visible object". it's just an object that can have visual properties. dosn't mean its a movie.

Philip Keiter
Senior Flash Software Developer
Sphyrras
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top