Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Extensions and Plugins > Components

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-12-2007, 03:57 PM   #1
Registered User
 
Join Date: Nov 2007
Posts: 45
Default How to add parameters to component built from scratch

Hi, I'm new to Flash 9 and I don't know how to add parameters to a Flash 9 component (one I created not extending UIComponent) via the Component Definition dialog box when my component uses a class file.

The second I enter a class path for the component, it wipes out any created variables. I'm trying to create a simple label component that's not based on the fl.core.UIComponent class. I just want to see what's the simplest component I can create.

All I want the component to do is display a colored background with a text field on top whose value I can change from the inspector. It doesn't need to resize, change state or anything. I figured I could do this without the overhead of the UIComponent, more as a learning exercise, but I've had no luck and would appreciate any help.

Or, am I getting this all wrong. Is it that when you have a class associated with a component, any variables must be created in the class file and then they'll magically appear in the component parameters inspector. (I assume if I were basing this on UIComponent, I could take advantage of the Inspectable metadata structure, but I suspect I don't have that route.)

In Jeff Kamerer's tutorial, he says you have to add the path to the UIComponent class to the document settings, but since I'm not extending this class, it doesn't make sense to me to do this.

Admittedly, I really should just extend the existing label component, but my experience from Flash 6 is that any component I made was way faster than the pre-built components.

Thanks,

Jennifer

PS I'd also like to know how I can reference a parameter added through the component definition dialog box. Is it the same as a parameter declared in the
petkusj@virtualight.com is offline   Reply With Quote
Old 11-12-2007, 04:58 PM   #2
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

I'm replying to myself. I'm beginning to suspect that a user-created component based on a class has to use the metadata [Inspectable(defaultValue="")] followed by get/set structure to show up in the component parameter structure. Now all I need to know is whether the metadata structure is created through the fl package or is a higher-level feature.

Again, thanks,

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 11-13-2007, 04:26 AM   #3
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Another reply to myself. I went ahead and used the [Inspectable] metadata structure and then goofed it up by trying to cram DataProvider (I think you only use this for array like structures) in there. I looked at the official Label component and they have a much simpler way of taking the parameters and inserting them into the component.

My guess is that you really can't create components from scratch anymore. You almost have to take existing components and extend them.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 11-13-2007, 04:53 PM   #4
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

And the final reply to myself. I'm still extending UIComponent but that's about it, and I've added an [Inspectable] metadata structure, using a get/set function pair to update a parameter I declare.

Code:
package com.virtualight.examples{
	import flash.display.Sprite;
	import fl.core.UIComponent;
	import flash.text.TextField;

	public class myLabel extends UIComponent {
		public var label_txt:TextField;
		public var defaultLabel:String = "My Label";
		public function myLabel() {
			super();
			labelname = defaultLabel;
		}
		override protected function configUI():void {
			super.configUI();
			label_txt = new TextField();
			addChild(label_txt);
		}
		[Inspectable(defaultValue="My Label")]
		public function get labelname():String {
			return label_txt.text;
		}
		public function set labelname(value:String):void {
			// Value is the same as what is already set.
			if (value == labelname) {
				return;
			}
			// Value in the PI is the default.
			if (componentInspectorSetting && value == defaultLabel) {
				return;
			}
			label_txt.text = value;
		}
	}

}
What I hadn't realized earlier is that the metadata/get/set function pair declares the parameter/variable. If you want to set the type of the parameter, you do that in the [Inspectable(defaultValue="Label", type="String")].

I realize this is probably old hat for everyone else, but I'm finding it instructive to try to create a component from scratch. Yes, I'm still extending UIComponent, but next I'll just try extending MovieClip and see if the metadata structure still works.

One thing that had me really confused is that the built-in Label component uses the word text as the parameter name, which is really confusing that you can use a reserved word as a parameter name. And the Jeff Kamerer tutorial similarly uses dataProvider as a parameter name. The Flash script editor clearly shows these two as reserved words.

Jennifer

PS Oh, and if you use the clean up formatting button in the script editor, it adds a semicolon at the end of the metadata, which really screws up things.

PPS Again, I don't know why I'm telling this to other people who may have already figured it out, but writing it down here helps cement the idea in my brain.
petkusj@virtualight.com is offline   Reply With Quote
Old 12-03-2007, 09:43 AM   #5
nvkms
Registered User
 
Join Date: Dec 2007
Posts: 1
Default

Thanks for posting though. It feels reassuring to see we're following the same procedure. Still having mixed feelings about Component support in CS3. Sometimes it seems to work if you get the hang of it. More than often it looks like a total embarassment... Still, CS3 is a great product.
nvkms is offline   Reply With Quote
Old 12-03-2007, 05:26 PM   #6
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Quote:
Originally Posted by nvkms View Post
Thanks for posting though. It feels reassuring to see we're following the same procedure. Still having mixed feelings about Component support in CS3 ...
Yeah, I think this will be really great once I understand it. It's just that all the books on the subject are silent about components. Only online do I find any information.

What's got me baffled right now is trying to pass color information through the Inspectable definition. If you use a type of Number, as in

[Inspectable(defaultValue = 0xffffff, type="Number")]
public set fontcolor(value:uint) ...

then in the Parameters inspector, it actually shows 0 as the default value (because I think that is the default value for the number class) and if you try to put in a hex color value, it just ignores you and sets it back to 0.

So the only real way to send in a hex value is to change the Inspectable type to String and then cast it as a uint. Where that becomes tricky is trying to create a get method, because I don't think you can have a set that accepts a String and a get that returns a uint.

I'm beginning to suspect the only way to do this is with a List and constants that hold my color values.

This is frustrating because while I'm trying to learn this, I usually go the simple route first: type in a color value, then get fancy with a pull-down list.

Oh well, I'll take a look at other Flash component sources and see how they get/set colors.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 12-03-2007, 05:30 PM   #7
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Argh! I feel so stupid because I'm replying to myself again.

Color is one of the parameter option types for Inspectable. I just got confused because everywhere else I store a color value I use a uint!

Just need to read Jeff Kamerer's tutorial more closely.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 12-03-2007, 09:33 PM   #8
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

I have figured out how to add, get and set a color property, but now I'm afraid things are a little out of order and I would appreciate someone setting me on the correct path.

I'm trying to create a simple label component. It's easy enough to change the text of the label with a get/set because the contents of a text field can be changed at any time.

But it seems the color has to be defined before the constructor creates the text field. Otherwise the textfield (via TextFormat) is just created with the default color.

Or am I approaching this the wrong way? Should my font color setter function dispatch an event that the color has changed? And does this mean I need to create an event class for this possibility.

Or is this one of those things that magically sending out invalidate() will fix?

Or, and I think I know the answer, do I have to do all these things and also add a draw function (overriding the UIComponent's draw function)?

(I guess this also means the actually text formatting should also be done in the draw function.)

Thanks,

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Old 12-03-2007, 10:11 PM   #9
delda
Registered User
 
Join Date: Jul 2006
Posts: 9
Default

ol
all what u get from here just ur voice
really NO ONE CAN HELP AT ALL
delda is offline   Reply With Quote
Old 12-03-2007, 11:04 PM   #10
Registered User
 
Join Date: Nov 2007
Posts: 45
Default

Well, all I can do is help myself!

I did create an event class and dispatched an event from the setter function (after remembering to import DataChangeEvent).

And I added a listener for the event in an overridden configUI (I actually created the text field via addChild and applied the TextFormat in this method).

So, I'm kind of creating the label and then immediately changing it after the setter determines what the fontcolor will be. I still think this is backward. I should be able to delay creating my label until I've obtained the font color (must ignore temptation to use a Timer).

Next, I have to figure out adding a draw function and then Invalidation.

Jennifer
petkusj@virtualight.com is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
add events DateChooser component?? ball420 ActionScript 2.0 0 10-12-2007 03:18 PM
passing a reference / variable to a Custom Component ljonny18 Flex 2, 3 & 4 1 08-07-2007 04:57 PM
Scrollpane component inside a window component marcusg Components 2 04-07-2005 04:20 AM
dynamic component (radiobutton) with setChangeHandler problem tROCK Components 6 08-25-2004 04:49 PM
help needed referencing a component instance inside my own custom component bleepbloop Components 4 08-06-2004 10:31 PM


All times are GMT. The time now is 12:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.