Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Creating A Component Within A Component Class



Basically I have a component with I have associated a class with - and then attached it to stage using attachMovie and make references to it using its linked name which works great. However within this class I want to attach another movie clip component - which works however how to I reference this second component from this class using linkage doesnt work neither does assigning it to variable. The only way is to call the class - which gives undesired results.


What is the proper way to have a component within a component?



FlashKit > Flash Help > Flash ActionScript
Posted on: 09-07-2005, 05:09 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Creating A Component
is it possible to use a masking layer inside a custom component? if so, is there some kind of trick to it?

Creating A Component
i need some help, people...

i would like to make a simple component: a link.

i couldn't understand the tutorial here on components... so i'm asking you guys for assistance...

i just want it to have:

Label property ( for the text you see in the link)
LinkTo property (where the link should point at)
FontName (the font to be used for the link)
FontColor (just the color of the text in the link)

i was thinking of creating a symbol, perhaps a button and then just create multiple copies of it, changing the link and the label...

but is that wise to do? i also just want to get started on how to make a component, though as simple as this.

all help will be appreciated. thanks, everyone!

Creating A Component
How do I create a component?... I want the component to consist of a button where I can change the Label, color, etc. in the parameters ?

Thanks!

Nathan

Creating Component
Hi,

This is the first time I'm trying to create a component. This component is just a simple box (window) consisting of a title.

What I have done so far is drawing a box, plant a dynamic textbox (Var: title) and converting these to a movieclip.

Then in my library, i right click the movieclip and input some Component Definition:


PHP Code:



|   Name    |     Variable    |    Value    |    Type
-----------------------------------------------
     Title     |      boxTitle   |   Box Title |   default
    Width    |     boxWidth  |    10         |  default
    Height   |     boxHeight  |    10        |   default
----------------------------------------------- 




After which, I added this code to the first keyframe within the movieclip:


PHP Code:



#initclip
function Box( )
{
    this.update( );
}

// Allow TriangleClass to inherit MovieClip properties
Box.prototype = new MovieClip( );

// Update draws the triangle at the current base and height values.
Box.prototype.update = function( )
{
    this.title = boxTitle;
    this._xscale  = 10 * boxWidth;
    this._yscale  = 10 * boxHeight;
}

// Connect the class with the linkage ID for this movie clip
Object.registerClass( "FBox", Box );
#endinitclip 




That's it. But no matter how I change the value in the properties and preview it, it will never change the width or height or title.

Thanks for any ideas.

Creating A Button Component
(Original post)

Ok, im being a n00b here, I dont yet fully understand Action Scripting, or Advanced Flash (Using MX 2004).

I've been doing load of tutorials and so on, I could get them to work, yet I was still left without fully understanding the creation of Button Components, all I want to do is create button icons, small little 21px X 21px icons, but can't find a way to do properly, and have it as a fully functional button component.

Can someone please help. Please.

Problem Creating Component
hi! i'm trying to create a simple component like a button. all seems to be working fine, the only problem is that anything i put on "avatar layer" doesn't disappear when compiling. here's my class code


Code:
package {

import flash.display.MovieClip
import flash.display.Sprite
import flash.text.*
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import flash.events.MouseEvent;

public class boton extends Sprite {

private var glyphName: String;
private var glyph: Sprite;
private var glyphSpace: Number;
private var texto: TextField;
private var formato: TextFormat;
private var tipo: String;
private var ancho: Number;
private var alto: Number;
private var clipBoton: Sprite;
private var textoTrans: String;


public function boton() {}


private function seteos():void {

var glyphTop:Number;

switch (tipo) {
case "PP":
ancho=80;
alto=70;
glyphSpace=20;
glyphTop=15;
clipBoton = new botonPP() as Sprite;
break;
case "P":
ancho=133;
alto=62;
glyphSpace=15;
glyphTop=10;
clipBoton = new botonP() as Sprite;
break;
case "G":
ancho=210;
alto=58;
glyphSpace=25;
glyphTop=15;
clipBoton = new botonG() as Sprite;
break;
default:
tipo="M";
ancho=162;
alto=58;
glyphSpace=25;
glyphTop=15;
clipBoton = new botonM() as Sprite;
}

addChildAt(clipBoton,0)

if (tipo != "PP") {
var fuente:Font = new Bell();
formato = new TextFormat()
formato.font=fuente.fontName
formato.color=0x000000
formato.size=16
formato.align="center"

texto = new TextField()
texto.embedFonts=true;
texto.antiAliasType = AntiAliasType.ADVANCED;
texto.selectable=false;
texto.defaultTextFormat=formato;
texto.text = textoTrans;
texto.width=(glyphName!="nada")?ancho-(glyphSpace+50):ancho;
texto.height=30;
texto.x=(glyphName!="nada")?(glyphSpace+35):5;
texto.y=glyphTop+5
addChild(texto)
}

if (glyphName!="nada") {
var loader:Loader = new Loader();
loader.load(new URLRequest(glyphName));
glyph = new Sprite()
glyph.addChild(loader)
glyph.x=glyphSpace;
glyph.y=glyphTop;
addChild(glyph)
}
addEventListener(MouseEvent.MOUSE_OVER,mouseOver)
addEventListener(MouseEvent.MOUSE_OUT,mouseOut)
}

private function mouseOver(e:MouseEvent):void {
var filtro:Array = new Array();
var glow:GlowFilter = new GlowFilter(0x0098FF,0.5,6,6,2,1);
filtro.push(glow);
clipBoton.filters=filtro;
}


private function mouseOut(e:MouseEvent):void {
clipBoton.filters=[];
}


[Inspectable(defaultValue="", type="String")]
public function set label(txt:String) {
textoTrans=txt;
if (glyphName && tipo) seteos();
}

public function get label():String {
return texto.text;
}

[Inspectable(defaultValue="", type="String")]
public function set grafico(txt:String) {
glyphName=txt;
if (textoTrans && tipo) seteos();
}

public function get grafico():String {
return glyphName;
}

[Inspectable(defaultValue="M", type="String")]
public function set tamano(tam:String) {
tipo=tam;
if (glyphName && textoTrans) seteos();
}

public function get tamano():String {
return tipo;
}

}
}


thanks!

Creating A Flash Component To Use In .NET
hi all,
i want to create an swf and then use it in a vb.net application.
the problem is:
can i allow to .net to access to the local variable of the swf.
means i have some local variables in the swf and i want that the vb.net can modify those variable.
is this possible?

thanks for all.

Creating A 'high-def' AV Component
I'm working on a virtual classroom videochat application for Communication Server MX. I'm about 4 days into my experience with Flash Comm and I'm not very far along.

The application calls for four small live video spots for the professors who are presenting and on larger video spot for the classroom camera. I've tried doing this using Flash MX' AVPresence component linked to the simple connect component. This setup works but gives end-users horrible video quality.

I've read around and found that the problem is that I am essentialy stretching the video by specifying a larger size than the default at that is the source of the distortion and pixelation. I also found many people who suggested that the solution was to build a custom video component that allows enlarging the feed.

So far I can't find any sort of guide that suggests I can do this or explains how. I've got pages of documentation but I don't know enough about the stuff to sort out where to start piecing together this component.

Can anyone give me or direct me to some good resources or tutorials for creating a higher resolution video component?



























Edited: 01/22/2007 at 08:46:39 AM by Jason CG Civie

Creating Flash Cs3 Component
Hi,
There is great and easy way to create flash based component in flash cs3 using action script 3.0.

I am going to make a simple My button component which will behave likely same as flash native button component.
You can modify this according your requirement this is just you give an idea about how we can go for creating a component in flash cs3.
Follow these steps…

1.Create a fla file and save this file with any name
2.Create a movieClip and draw a rectangle shape on first frame.
3.Right click on movieclip in library, select linkage
4.Provide class name in text field area [MyButton] (you can use any name here which should matched with your class)
5.Click Ok button
6.Write class [MyButton]
(you can copy and use this)
/**
* author @ sanjeev rajput
* sanjeev.kr.rajput@gmail.com
* A flash action script 3.0 based component without extending UIComponent class
**/
package {

import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.motion.Color;
public class MyButton extends Sprite{

private var _tf:TextField;
private var _Label:String="My Button";
private var _bgColor:uint=0xCCCCCC;
private var _rollOverColor:uint=0xFFCCCC;
private var _borderColor:uint=0x000000;
private var _borderThickness:int=1;
private var _width:Number = 100;
private var _height:Number =100;

private var _background:Sprite;

public function MyButton() {
init();
createChildren();
initEventListeners();
draw();
}
//-------------property section [Start] -----------------------
[Inspectable]
public function set Label(lbl:String){
_Label=lbl;
draw();
}
public function get Label(){
return _Label
}

[Inspectable]
public function set bgColor(color:uint):void{
_bgColor=color;
draw();
}
[Inspectable]
public function set borderColor(color:uint):void{
_borderColor=color;
draw();
}
[Inspectable]
public function set borderThickness(thickness:int):void{
_borderThickness=thickness;
}
[Inspectable]
public function set rollOverColor(color:uint):void{
_rollOverColor=color;
}
//-------------property section [End] -----------------------

private function init():void {
trace('welcome');
_width = width;
_height = height;
scaleX = 1;
scaleY = 1;
removeChildAt(0);
}
private function initEventListeners():void{
addEventListener(MouseEvent.MOUSE_OVER, eventHandler);
addEventListener(MouseEvent.MOUSE_OUT, eventHandler);
}

private function eventHandler(event:Event):void{
if(event.type == MouseEvent.MOUSE_OVER){
toggleColor(_rollOverColor);
}
if(event.type == MouseEvent.MOUSE_OUT){
toggleColor(_bgColor)
}
}

private function createChildren():void {

_background = new Sprite();
_tf = new TextField();
_tf.autoSize = "center";
_tf.selectable=false;

addChild(_background);
addChild(_tf);
}

protected function draw():void {

toggleColor(_bgColor);

_tf.text = _Label;
_tf.x = Math.floor((_width - _tf.width)/2);
_tf.y = Math.floor((_height - _tf.height)/2);
//width = _tf.width;


}

private function toggleColor(color:uint):void{
_background.graphics.clear();
_background.graphics.beginFill(color, 1);
_background.graphics.lineStyle(_borderThickness, _borderColor, 1);
_background.graphics.drawRoundRect(0, 0, _width, _height, 10, 10);
_background.graphics.endFill();

}

public function setSize(w:Number, h:Number):void {
_width = w;
_height = h;
draw();
}

}
}

7.Now right click again on your movieclip in library and select component definition.
8.In class name text field provide same class name [MyButton]
9.Click on ok button
10.Right click again on movieClip in library and select Export SWC file.
11.Same your exported SWC file in (For window only) [c:Documents and Settings$userLocal SettingsApplication DataAdobeFlash CS3enConfigurationCommands
12.Now just open another new flash file open component panel/window reload component you will your component in component panel with MyButton name.
13.Drag your custom component on stage provide inputs form property window and text it.
Enjoy!

2 Questions On Creating A Component
Hi. I am learning how to make a component, and for fun, am in the middle of creating one for a FLV Player. (much like the one already in the components panel but with a different skin).

I have two questions for this.

1. I have written all my actionscript within the movie clip itself. Now i am asking myself if i should have written it in a seperate .as file. If not, what is the benefit of a .as file? If so, then why when it appears to work fine without one?

2. The second question is a little complicated to explain, sp please let me know if i do not make sense.

My actionscript contains functions to position certain elements. This worked fine until i resized the component instance on the stage. Then the seperate elements moved all over the place. On further inspection i found that when scaled, the measurements stayed the same.

(eh? i hear you say). let me try to explain. The width of the component - at 100% scaling - is for example 200 pixels wide. (I place a dynamic text box in the middle which dynamically shows the width of a single element spaning the entire width of the movie clip.) I have also placed a play button 10 pixels from the left. If i resize the component on the stage at authoring time to 400 pixels (200%), i would expect the width value in the text box to say 400px. However, it still says 200px.

Because i want the play button to appear 10px from the left - regardless of overall size of the resulting movie - the actionscript now needs to set the x value to 5px.

I solved this problem by writting the following code for each element Code:

this.playButton._x = 10 * (finalised width / original width)

This works but is very messy with lots of elements. I believe there must be a much better way of doing it, but it escapes me. Can anyone enlighten me?

I Got A Bad Issue Creating Component
Okay. So I'm creating new Pencil & Pen Tool -component, but I got a big issue when adding this line:
Code:

duplicateMovieClip(_path, "_newCursor", this.getNextHighestDepth());

Code isn't ready yet, but if I remove that line, it will works fine. But if I place that line, Flash will give me this kind of warning in output panel, when checking everything is okay:
**Error** C:HeikkiGodalaComponentsPen & Pencil ToolPenAndPencilTool.as: Type mismatch.

Total ActionScript Errors: 1 Reported Errors: 1

[HELP] Creating Component In MX 2004
I am trying to create component in MX 2004 and export it to SWC

In the Component Definition, whenever I insert the class name into AS2.0 class field, I cannot put parameters, they just simply get removed.

Why?

Creating A Component With No Initial State
I am creating a component which will build a menu based on the contents of a XML file, the XML file can be defined within the components properties and then it works...hopefully

i have created the code in non-component mode (ie code and graphics!); but am thinking about the final export, there wont be anything to attach the class to and therefore export as a component as all the graphics are created at run time.

should i just create a basic graphic (like the connection thing used by macromedia) and attach the class to that so it can be dragged on stage?

hope that makes sence, any input would be great!!

AS2 Help: Component, Creating Scrollbar. Bugs
this is my second post.. weird - the post yesterday is gone. when i search for it it is as if someone deleted it.

anyway, here goes:

I created this component, and generally it works fine. I wanted the scrollbar to work as when the mcContent's size changes.

confused? let me explain a bit:
on the main stage there are mcContent, mcWindow, mcScrollbar and the mcSlider.

The mcContent is masked by mcWindow. The scrollbar controls how far the mcContent should be to make it appear as if the it's scrolling down.

The mcSlider just makes the mcContent bigger and smaller.

As you can see, when you change the size of the mcContent using the slider, and then you scroll using the mcScrollbar, it doesn't work as expected.

There are a number of bugs and I'm exhausted from trying to solve them. This is where I need the gurus' help.

I know it might look a little messy but it's all divided into functions so maybe 10 minutes of looking at the code and you'll understand it.

Required: knowledge on how to make components. The mcScrollbar automatically reads from components.Scrollbar whose located is defined by EDIT > PREFERENCES > ACTIONSCRIPT TAB > Language Box > classpath:
C:...flashResourcesASClasses

THanks!

Creating A Filter For The List Component
Any1 know how can I create a filter for the list component?

Creating A Resizeable, Non-distorting Box Component
Hi Guys,

When you use some of the standard Flash UI components, i.e. ComBox, you drag-n-drop it on the stage, and when you resize it, the box does not get twisted or similar, it simply repositions the content within it.

Does anybody of you know how to make a similar feature myself?

The reason that I am asking is, that we are using a common box, with specific color, rounded corners and shadeds a lot on our site, and I would like to build a component, so that I can simple drag-n-drop boxes, without the lines changing thickness, the corners changing shape...but still being able to resize within the Flash editor and not having to publish each and every time to see the changes.

Thx for your help,
Mads

Creating Own Text Scrolling Component?
Hey all,

I was wondering how I could make one of my MovieClips scroll throught a textbox like the scrolling component that comes with the program. I have the textbox and the MovieClip, all I need to know is the actionscript, or where I could find out how to do this.

I have done a little research and found out that skinning an existing component seems to be the way to go. However, can I get around this by just addiing some actionscript to a MovieClip or something like that? Or am I trying to make things harder for myself?

Thanks for taking the time to read this,
Greenham.

[F8] Help Creating Dynamic Instances Of Component
I have created a component called tab which I'm using in another movie. In the main movie, the linkage identifier for the tab component is called tab. I'm trying to create an empty movie clip and then create a dynamic amount of instances of this tab component and attaching them to the empty movie clip but it's not quite working. It is creating an instance fo the component, but I can't figure out how to set the properties of the component such as it's x coordinate or any of the defined parameters I created when building the component. Here's the script I have... can anyone see why it's not working? Thanks.


Code:
function SetupTabs()
{
var tabs = new Array("tab1","tab2","tab3","tab4");
createEmptyMovieClip("container",1); //main clip to hold all tabs
for (i = 0; i < tabs.length; i++)
{
initOb = {BGColor:"#37527E",FontColor:"#ffffff",Link:"test.htm",LinkTitle:tabs[i],OverBGColor:"#990000",OverTextColor:"#000000"}; //custom properties of the tab component
container.attachMovie("tab", tabs[i], 2, initOb);

if (i > 0) //position next tab to the right of previous tab
container[tabs[i]]._x = container[tabs[i-1]]._x + container[tabs[i-1]].Width;
else
container[tabs[i]]._x = 75;
}
}

[CS3] Creating A Component - Easy Question
I'm using Actionscript 2, and would like to create a component

I essentially want to make a checkbox that holds a variable's name as one of its parameters, and is either checked or unchecked (which I'm assuming is a simple gotoAndStop) based on that variable's value

I can figure all that stuff out, I just need a good tutorial on how to set up a component, as I'm completely new to them, and can't seem to find a good one

Tutorial: Creating A SWC Component In FlashDevelop
If you use the open-source IDE FlashDevelop this tutorial may be helpful: Creating a SWC Component in FlashDevelop.

Error When Creating New Datagrid Component
I'm trying to create a new datagrid component with the instance name documents_dg. I've created the datagrid on stage but and added the folowing actionscritp code:


Code:
var documents_dg:DataGrid;
documents_dg.columnNames = ["1","2"];
but when I'm trying to test the movie I get the following error

[error]
**Error** Scene=Scene 1, layer=actions, frame=1:Line 46: The class or interface 'DataGrid' could not be loaded.
var documents_dgataGrid;

Total ActionScript Errors: 1 Reported Errors: 1
[/error]

Does anybody have a clue what is causing this error?

thnx.in.advance.marijntje

Thinking Of Creating A New DataGrid Component
Hi, Im thinking of creating a new datagrid component... to have it as customizable as possible, it will definately help me in my future projects. Does anyone know something similar which is out there which I can probably reuse? Or maybe there is already a better datagrid class that I dont know about?

Thanks!

PS did anyone try to make one? looks like its gonna be a complex task.

Creating A Preloader For The LOADER Component
hey all,

I am creating a photo gallery using the loader component, however some of the jpgs are around 240k so I want to add a custom preloader. The issue I am having trouble with is... how do I set up a preloader that I have made to activate when the loader component loads a new jpg via the myLoader.contentPath = "sample.jpg"???

I am using a sliding thumbnail gallery w/ a static main image behind.

Anyone have a tip for settingup a preloader for the loader? Never had much luck making preloader.
THX

Initializing A Class/Component - Am I Doing This Right?
I'm trying to build a standard Pop Up confirmation window that I can use throughout my application. I created a MovieClip Symbol in the library called PopUpBox, and then I put this actionscript on it's first frame so I can use it as a class and call methods on it like 'setLabel()'.

Right now I'm just setting a default label in the init function, but that's not showing up in the window. I'm also trying to call the setLabel method from my main movie, but that's not working either. Can somebody have a look-see and tell me what I might be doing wrong?



Code:
#initclip

function PopUpClass(){
this.init();
}

Object.registerClass("PopUpBox",PopUpClass);
PopUpClass.prototype=newMovieClip();
PopUpClass.prototype.init=function(){
this.txtLabel.text = 'wuz up mang';
}

PopUpClass.prototype.setLabel = function(lbl){
this.txtLabel.text = lbl;
}

PopUpClass.prototype.getLabel = function(){
return this.txtLabel.text;
}

#endinitclip
stop();



Thanks, Adam.

Class/Component Question
I am making a class that is suppose to control key board mapping. I want to use the onClipEvent(keyDown) function for and instance of this class. I can't seem to get it to work. I can use AppSimClass.porotype.onEnterFrame = function () {} but I tried this approach before and it is too sensitive to key presses. Is there any way to use an onClipEvent for a instance of a class?

How To Get Event In Component Class?
Hello,

I want to make ActionScript 2 component. I have one movie clip (my component). Inside it I have ComboBox with instance name myMovieClip. The class associated with component is

Code:
class mypackage.MyComponent extends Object{

static var symbolName:String = "parser.Deroulateur";
static var symbolOwner:Object = parser.Deroulateur;


private var myMovieClip:MovieClip;

function MyComponent(){

}

function change():Void{
trace("change");
}

}
I want to work with event change of the ComboBox. If I put it on the ComboBOx instance like this:

Code:
on(change){
trace("change");
}
it works OK but how to get it in my class? I tried with method

Code:
function change():Void{
trace("change");
}
but it just doesn't work

Please help.

Thank you

Using Tree Component In Class
Hi,
I am trying to use a tree component in flash mx 2004.
I am able to populate a tree compoenent with XML data.
On clicking of a leaf node I am updating the contents of the leaf node in a datagrid.
Alls happening fine as long as I code it in an fla document.
The moment I convert the code into a class nothing seems to happen.

Infact the constructor of the class is also not getting called. Neither can I set an breakpoints in debugg mode.

Heres the code
--------------------------------------------------------------------------


Code:
import mx.controls.Tree;
import mx.controls.DataGrid;
class treeNav extends MovieClip {
private var listArray:Array;
private var xml:XML;
private var myTree:Tree;
public function treeNav() {
var temp = this;
listArray = new Array();
xml = new XML();
xml.ignoreWhite = true;
xml.load("contact info.xml");
xml.onLoad = function() {
temp.createTree(this);
};
trace(this);
}
private function createTree(x:XML) {
myTree.dataProvider = x.firstChild.firstChild.firstChild;
trace(x);
}
public function createdata(x:XMLNode) {
var a = new Array();
for (var i in x.attributes) {
a[i] = x.attributes[i];
}
listArray[0] = a;
}
}


I have created a tree component on stage inside a movieclip and attached the above class to the movieclip.
The problem seems to be at line number 6 "private var myTree:Tree;" where I am storing a refernce to the tree compoenent on stage by the name "myTree". The moment I comment this line the constructor is called.

Not sure what is this issue,

please help.

Component And Tween Class Help
Hi All,

I have a simple component which is dynamically added to a movieClip (‘parent_mc’) and is then made a listener of that movieClip. I’m creating 5 different component instances and each one is given a unique ‘id_number’. The component uses a tween calss function for moving to a different x position. The ‘parent_mc’ broadcasts a message (this.broadcastMessage("moveComp", compId, newX); and only the component with the matching id moves to the new position.

Everything works as expected but the problem I’m having is trying to call a function to let the 'parent_mc' know when the tween has finished. Can anyone help??

Thanks,
Ty

This is a cut down of the components script.









Attach Code

#initclip
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
myCom.prototype.moveComp = function(compId, newX) {
if (compId == this.id_number) {
trace("moving component "+this.id_number);
var myTweenX = new Tween(this, "_x", Regular.easeOut, this._x, newX, 0.2, true);
myTweenX.onMotionFinished = function() {
// trace works but the id_number is undefned
trace(“move finished”+this.id_number);
// calling a ‘parent_mc’ function or a function in the component doesn’t work!!
this._parent.moveFinished(this.id_number);
this.moveFinished();
};
}
};
//
myComp.prototype.moveFinished = function() {
trace (“finish moving ”+this.id_number);
};
//

Using Tween Class In A Component
hi, I have made a list menu component and it uses transitions.Back tween when open and close. Before compiling as SWC, that is as a movieclip, the component works well but after compiling as swc and import in another document, tween functions does not work. Why can I not use this classes in a component? Here is the code :

#initclip
import mx.transitions.Tween;
import com.robertpenner.easing.*;
//---------------------------------------------------------------------------------------
//constructor
function MultiListMenuClass() {
this.isOpen = false;
this.columnNumber = -1;
}
//---------------------------------------------------------------------------------------
//inherit from the MovieClip Class
MultiListMenuClass.prototype = new MovieClip();
//---------------------------------------------------------------------------------------
//methods
MultiListMenuClass.prototype.open = function() {
openTween = new Tween(this, "_y", Back.easeOut, this._y, this._height-40, 0.5, true);
this.isOpen = true;
};
MultiListMenuClass.prototype.close = function() {
closeTween = new Tween(this, "_y", Back.easeIn, this._y, 0, 0.5, true);
this.isOpen = false;
};

Attach Component Within A Class
Hello,

i'm looking for a way to add an instance to a component from a class...
Something like


Code:
class myClass extends MovieClip{
function myClass(){
}
function addComponent(){
attachMovie(thecomponent, "compoInstance", 0, 0, 1);
}
}
but i dont know about the "thecomponent" part.. i tried "textInput" but it doesn't work.. any idea?

Help With Component And Tween Class
Hi All,

I have main movieClip which creates several instances of a library component each with a different id_number variable. The components are made listeners of the main movieClip so when it broadcasts moveComp(id_number,newX) only the matching component respond and moves to the new x location.

Everything works fine but the problem I have is trying get the tween class onMotionFinished to call a function either in the parent movieClip or a function in the component itself. What am I doing wrong? Can anyone help??

Many Thanks,
Ty


This is the relevant bit of the components script.

Code:
//---------8<-----
myCom.prototype.moveComp = function(compId, newX) {
if (compId == this.id_number) {
trace("moving component "+this.id_number);
var myTweenX = new Tween(this, "_x", Regular.easeOut, this._x, newX, 0.2, true);
myTweenX.onMotionFinished = function() {
// trace works but the id_number is undefned
trace(move finished - +this.id_number);
// calling a parent_mc function or a function in the component doesnt work!!
this._parent.moveFinished(this.id_number);
this.moveFinished();
};
}
};
//
myComp.prototype.moveFinished = function() {
trace(move finished - +this.id_number);
};
//---------8<-----

Component Add In A Class And Use Object
Hi

I m creating a common class of component which i want to use in different class .
In My project i have a color.as class in which i had create a colorPicker and added it.Now i want to use it into many class where i could access all method of colorPicker without adding colorPicker Component into all class . Can it possible

Thanks

How To Get Event In Component Class?
Hello,

I want to make ActionScript 2 component. I have one movie clip (my component). Inside it I have ComboBox with instance name myMovieClip. The class associated with component is

class mypackage.MyComponent extends Object{
    
    static var symbolName:String = "parser.Deroulateur";
    static var symbolOwner:Object = parser.Deroulateur;
    
    
    private var myMovieClip:MovieClip;
    
    function MyComponent(){
    
    }
    
    function change():Void{
        trace("change");
    }
    
}


I want to work with event change of the ComboBox. If I put it on the ComboBOx instance like this:

on(change){
    trace("change");
}

it works OK but how to get it in my class? I tried with method

    function change():Void{
        trace("change");
    }


but it just doesn't work

Please help.

Thank you


Component Instance Name In A Class?
I am a longtime user of a very useful tool http://www.slideshowpro.net a slideshow component that has a really great API.

To use it you need to drag the component to the stage and give it an instance name in the properties pane, I'm using my_ssp. I have always coded this stuff on the first frame of the time line, such as setting the position of a TextField in relation to the component instance on the stage.

Code:

_galleryTextField.x = my_ssp.x;
_galleryTextField.y = my_ssp.y - (_galleryTextField.textHeight * 2) ;


So I had the need to create a class that will create the TextField "_galleryTextField" so I can access it as a public var in other places of my project. Here's the problem, now that I need to access the my_ssp instance name inside of this new class, It becomes an undefined property. I have imported the appropriate package, but trying to figure out how to tell this class what my_ssp is? Normally I set the Linkage in the library to make it available, like with a MovieClip, but this is a component and I can't do that in the Library. I'm thinking I need to declare it as a public var in the document class, but then I'm not sure what to set the type to? Can I make a component's instance name available to a class or am I going about this completely wrong?

I hope this makes some sense, thanks for any help.

Creating A Unique Scrollbar-not A Boring Component One
hi,
need to know how to create a unique scrollbar as opposed to the boring flash UI component one.

here's an example of something like what i want to make:

http://www.cartoonfox.hostrocket.com/

any tips will be much appreciated.

Need Tutorial For Creating Simple A Flash MX Component
Anyone can tell me where i can find simple tutorial for creating flash mx component
plz. help me
Thanks

Problem Creating Dynamic Instances Of A Component
I have created a component called tab which I'm using in another movie. In the main movie, the linkage identifier for the tab component is called tab. I'm trying to create an empty movie clip and then create a dynamic amount of instances of this tab component and attaching them to the empty movie clip but it's not quite working. It is creating an instance fo the component, but I can't figure out how to set the properties of the component such as it's x coordinate or any of the defined parameters I created when building the component. Here's the script I have... can anyone see why it's not working? Thanks.


function SetupTabs()
{
var tabs = new Array("tab1", "tab2", "tab3", "tab4"); //tmp array
createEmptyMovieClip("container",0);
var prevTB:Object; //used for position - copy of previous tab object

for (i = 0; i < tabs.length; i++)
{
initOb = {BGColor:"0x37527E",FontColor:"0xFFFFFF",Link:"test.htm",LinkTitle:tabs,OverBGColor:"0x990000",OverTextColor:"0x000000"}; //initObject parameters for tab object
var tb:Object = container.attachMovie("MM_Tab", "tab" + i, i, initOb);
container._x = 65;

if (i > 0)
tb._x = prevTB._x + prevTB.Width; //position current tab to the right of previous tab
else
tb._x = 75;

prevTB = tb;
}
}

Creating Links To Flash Menubar Component
I am working on a flash website that requires the use of the flash preset MenuBar component, but have run into a little trouble assigning links to the separate labels that I have created. When the movie is tested, the many labels are separate; but how do you make each of them a different link? Please help.

Creating Links To Flash Menubar Component
I am working on a flash website that requires the use of the flash preset MenuBar component, but have run into a little trouble assigning links to the separate labels that I have created. When the movie is tested, the many labels are separate; but how do you make each of them a different link? Please help.

Creating Buttons From Symbol Versus Component
Why, when I add actionscript to a button created from a symbol, do I have to apply the code to the "On Release" event of the button to get it to work? Creating an event listener on the main timeline just ignores my code. Here's the example I'm using ...

I have a button created from two graphic symbols. I have designated the Up, Over, Down and Hit states, dragged an instance of the button to the stage and called it "btn". The states act as they ought but the action below is ignored:

var TestListener:Object = new Object();
TestListener.click = function() {
        trace("hello")
}
//add the event listener to the button
btn.addEventListener("click", TestListener);

If I drag a button component to the stage and apply the listener to that instance - no problem.

AS 2.0 AttachMovie In Component Class Function
I am trying to attach a movie dynamically to the stage and reference its variables from a response from a php script. This method works fine in regular timeline coding, but when it is in a component class, it wont attach the movies dynamically when the component loads up. Please help.

code:

import mx.core.*;
import mx.containers.*;
import mx.controls.*;
import mx.transitions.easing.*;
//Associate custom component image
[IconFile("Menu.png")]


//declare the class and identify the parent class

dynamic class mx.controls.Menu.phpMenu extends mx.core.UIComponent{



//identify the symbol name that this class is bound to
static var symbolName:String = "phpMenu";
//identify the fully qualified package name of the symbol owner
static var symbolOwner:Object = Object(mx.controls.Menu.phpMenu);
//provide the className variable
var className:String = "phpMenu";

//Declare all movieclips and properties going to be used in component
private var mainCategoryLoader:LoadVars;
private var subCategoryLoader:LoadVars;
private var mcHolder:MovieClip;
private var backGround:MovieClip;
private var scroller:ScrollPane;
private var scrollPaneContent:MovieClip;
private var subCategory:String;
private var i:Number;
private var nexty:Number;
private var randInt:Number;
private var _rootURL:String;
private var _fileName:String;
public var statusBox:String;
public var headerBox:TextField;


//constructor
function phpMenu(){}

//Create children
private function createChildren():Void{

}

//define init method for this component, and initialize super class
public function init(Void):Void {
super.init();
randInt = int(Math.random() * 123456789);
loadMainCategories(_rootURL, _fileName, randInt);
}

//Draw
private function draw():Void{
super.draw();
this.scroller.contentPath = "scrollPaneContent";

}



//Introduce property inspector parameters
[Inspectable(defaultValue="menuLoad.php")]
public function set fileName(theFile:String){
if(theFile == ""){
trace("Please fill in a file name");
}else{
_fileName = theFile;
trace("file name is " + _fileName);
}
}

[Inspectable(defaultValue="http://")]
public function set rootURL(theRoot:String){
if(theRoot == "http://"){
trace("Please fill in a root directory.");
}else{
_rootURL = theRoot;
trace("root URL is " + _rootURL);
}
}



//declare main menu load function
public function loadMainCategories(u,f,r):Void{
mainCategoryLoader = new LoadVars();
mainCategoryLoader.handler = this;
mainCategoryLoader.sendAndLoad(u + f + "?" + r, mainCategoryLoader, "POST");
mainCategoryLoader.onLoad = function(success){
if(this.status = "ok"){
trace("loaded successfully");
trace("url is " + u + f + "?" + r);
nexty = 0;
trace("nexty is set to " + nexty);
this.headerBox.text = this.header;
for(i=0;i<this.mainCategoryCount;i++){
trace("i = " + i);
trace("header = " + this.header);
trace(this["mcHolder" + i]);
trace("nexty is set to " + nexty);
scroller.content.attachMovie("mcHolder", "mcHolder" + i, getNextHighestDepth());
//scroller.content["mcHolder"+i].subCategory.text = this["mainCategory" + i];
setProperty(scroller.content["mcHolder"+i],_y,nexty);

scroller.invalidate();

trace(scroller.content["mcHolder"+i]._height);
}

}else if(mainCategoryLoader.status = "error"){
trace("Sorry, loaded unsuccessfully");
statusBox = mainCategoryLoader.error;
}else{
trace("No response from Database");
statusBox = "Loading Menu...";
}
}
}

}

Using Component Inside Custom Class
Hi,

I'm creating a registration form that contains a ComboBox component.
This component works as expected on its own:
code:
import mx.controls.ComboBox;
for (var i = 1930; i <= 1990; i++)
{
year_cb.addItem({data:i, label:i});
}
var year_cbListener:Object = new Object();
year_cbListener.change = function(evt_obj:Object)
{
var item_obj:Object = year_cb.selectedItem;
trace(item_obj.data);
};
year_cb.addEventListener("change", year_cbListener);


But when I try to use it inside my custom class (wich will handle all the data of the registration), it simply doesn't work. The ComboBox doesn't even get populated:
code:
import mx.controls.ComboBox;
//
class Registration extends MovieClip
{
private var year_cb : ComboBox;
private var year_cbListener : Object
//
public function Registration ()
{
myInit ();
}
//
private function myInit ()
{
trace (year_cb); // works
for (var i = 1930; i <= 1990; i ++)
{
year_cb.addItem (
{
data : i, label : i
});
}
year_cbListener = new Object ();
year_cbListener.change = function (evt_obj : Object)
{
var item_obj : Object = year_cb.selectedItem;
trace (item_obj.data);
};
year_cb.addEventListener ("change", year_cbListener);
}
}

Here are the files (combobox working alone, and the class files).

Any ideas?
Thanks.

Getter/Setter Within A Class With A Component
I have a class file which loads comboboxes on the stage. In the interaction various things happen which need to be recorded, and I had done this in the past by setting properties on movie clips. I.E. -

mc1.propertyName = true/false;

I try to do that with a component and get a message saying that the property can't be created on fl.controls.ComboBox.

The property name is: isRed. It's being set like this:

combo1.isRed = true/false;

Here's the getter/setter:

public function get isRed():Boolean {
return _isRed;
}
public function set isRed(value:Boolean):void {
_isRed = value;
}


Also tried this:

[Inspectable(defaultValue=false)]

public function get isRed():Boolean {
return _isRed;
}
public function set isRed(value:Boolean):void {
_isRed = value;
}

Any ideas? Thanks.

Instantiating MXML Component Within AS3 Class
I have a MXML component that is pretty much this:

MXML Component name is "TestPlan.mxml"

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">

</mx:Canvas>
inside my AS3 I do this

pt:TestPlan = new TestPlan()
hbox.addChild(pt);

I get a TypeError #1009.

Can anyone help?

Accessing A Class Inside Of A Component
I would like to give the users of a component, that I am making, access to some of the classes being used inside of the component.

Is there a way to do this without distributing the source of this class?

Thanks.

How To Add Parameters To Component W/class Path
Hi, I'm new to Flash 9 and I don't know how to add parameters to a Flash 9 component I create via the Component Definition dialog box if 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.

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.

Thanks,

Jennifer

Oop As2 - Component - Problem With Referring Class To Itself
hello, im currently creating a component which calls on an xml file. i want a function from the class to be called once the xml is loaded, but i cant seem to target the function.


Code:
class className {

// variable
var inputXML:XML;

// constructor
public function className () {
this.init ();
}

// initialization
private function init () {
this.inputXML = new XML ();
this.inputXML.ignoreWhite = true;
this.inputXML.load ("xmlfile.xml");
this.inputXML.onLoad = function (success) {
if (success){
this._parent.setContent (this);
}
}
}

// functions
private function setContent (xml:XML) {
trace (xml);
}
}
logic suggests that since inputXML belongs to the class, it's parent should be the class. however, with the onload, it seems that it cannot reach its parent. i even tried without relating to the class (setContent (this) instead of this._parent.setContent (this)) and still doesnt work

what should i look for?

Targetting Problem In Class (Component)
So here we go. I'm kind of a stuck on creating AS2 component. Its my first one and I think thats probaply the reason im stuck in this stubid situation.

So lets move to the point. I have created Mouse listener which is working fine, only thing I just cant understand is how can I target to something inside of the listener when event is launched from it.

Heres a small example:


Code:
Class ..... extends MovieClip {

var changeMe:Number;

var theListener:Object = new Object();


function constructor(){
createMouseEvents();
}

function createMouseEvents() {
Mouse.addListener(theListener);

theListener.onRelease = function(){
// Here comes the problem
// For example im trying to give "changeMe" variable a new value
// but i cant target it.

changeMe = 10; // no luck
this._parent.changeMe = 10; // no luck

trace(this); // Equals to: [object Object] thats correct
trace(_parent); // Equals to: undefined
trace(this._parent) // Equals to: undefined

}
}
} // class ends
I hope I just havent missed anything cause im getting tired with this. I dont know are there other threads about this cause I cant get in my mind any search words for this.

Thanks in advance. Ill hope heres some AS hero (I know heres many).

And btw. love your tutorials. User them alot when I started with Flash and AS.

AS2 Class And Component Loading Problem
Hi all,

I'm testing this movie in flash 8. Here's how it's set up.
*I have a one frame preloader that works in the first frame.
*I'm exporting my AS2 classes to the second frame.
*I have all my components thrown inside a movieclip on the 11th frame so I don't have to export them to the first frame.

When I test the movie for high bandwidth, It goes to the frame that it's supposed to go, it connects to my remoting gateway, but the components don't show up. However, if I test the movie for 56k, the components show up, but it won't connect to my remoting gateway.
I've attached the zipped fla for your viewing enjoyment.

I've spent about 3 days on this problem, so any help will likely make me weep with joy.

Any Ideas?

Copyright 2005-08 www.BigResource.com, All rights reserved