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?
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 01-11-2006, 03:34 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Attach Class
I'm making a flash game and there are three frames. One is the intro, two is the actual game, and three is an ending screen. Currently, I only have the single game frame and I've attached a document class to the entire movie. How do I attach a class to a frame instead of the entire document?
Attach Movie Using Class
i want to attach movie any where so i want to built a class
class Class_AttachMovie
{
function create1(attachIN:MovieClip, movName:MovieClip, newName:String, newDepath:Number)
{
attachIN.attachMovie(movName,newName, newDepath);
}
}
there is some error of Type mismatch.
Attach Class Inside A MovieClip
hi,
i have created 2 classes 1.LoaderPane, 2.Annotation. in actionscript.
in LoaderPane there is another movieClip name __imageClip which is used to display image in it.
i want to attach the Annotation class inside this __imageClip. but the code is not working. if i attach the Annotation class inside the LoaderPane then it works fine. but i want it to be attached inside LoaderPane.__imageClip.
function someFunctionInsideLoaderPane():Void{
var i = __annotationCount;
var ann = this.attachMovie("Annotation","annotation"+i,this. getNextHighestDepth());
ann.DrawRectangle(x1,y1,x2,y2,i);
__annotationCount++;
}
Faraz
Class Trying To Attach A Movie To The Stage
I am just trying to attach a simple movieClip to the stage in a class file:
Code:
class ImageViewerMain extends MovieClip {
// Constants:
public static var CLASS_REF = ImageViewerMain;
// Public Properties:
// Private Properties:
// var to pass from constructor func to loadImage func
private var newlyCreatedImgHolder_mc:MovieClip;
// Initialization:
// set constructor func
public function ImageViewerMain(targetImg_mc:MovieClip, targetThumb_mc:MovieClip, depth) {
// create the empty movie holder with a unique instnace name and depth
for (var i = 0; i<_level0.numOfItems; i++) {
// use the array previously created to set the imageToLoad var
var newImageToLoad = _level0.imageArray[i];
var newThumbToLoad = _level0.thumbArray[i];
// create as many empty movieClips as there are images in the XML with unique instance names
makeImageMovieClips(i, newImageToLoad, targetImg_mc);
/*var newImgClip_mc = targetImg_mc.createEmptyMovieClip("imgHolder_mc"+i, depth);
var newThumbClip_mc = targetThumb_mc.createEmptyMovieClip("thumbHolder_mc"+i, depth);
// load the imageinto the newly created movieClip
newImgClip_mc.loadMovie(newImageToLoad);
newThumbClip_mc.loadMovie(newThumbToLoad);
newThumbClip_mc._x = newThumbClip_mc._x+100;
targetImg_mc.imgHolder_mc5._alpha = 0;
// set them all to 0 alpha
//newClip_mc._alpha = 0
*/
}
}
// Public Methods:
public function makeImageMovieClips(i, newImageToLoad, targetImg_mc) {
var imgMovieClip = ["img_"+i];
trace('imgMovieClip = '+imgMovieClip+' will load '+newImageToLoad);
_level0.attachMovie("movieHolder", "movieHolder_mc"+i);
//_level0.loadMovie(newImageToLoad)
//_level0.imgMovieClip._x = targetImg_mc._x+100;
//btn.onPress = function() {
//trace(this);
//};
}
public function loadImage(img:String):Void {
newlyCreatedImgHolder_mc.loadMovie(img);
}
// Semi-Private Methods:
// Private Methods:
}
The linkage is this: movieHolder
What am I doing wrong? Thanks, dvl
Attach Class Inside A MovieClip
hi,
i have created 2 classes 1.LoaderPane, 2.Annotation. in actionscript.
in LoaderPane there is another movieClip name __imageClip which is used to display image in it.
i want to attach the Annotation class inside this __imageClip. but the code is not working. if i attach the Annotation class inside the LoaderPane then it works fine. but i want it to be attached inside LoaderPane.__imageClip.
function someFunctionInsideLoaderPane():Void{
var i = __annotationCount;
var ann = this.attachMovie("Annotation","annotation"+i,this. getNextHighestDepth());
ann.DrawRectangle(x1,y1,x2,y2,i);
__annotationCount++;
}
Faraz
Attach More Than 1 Movie Clip From 1 Class
hi what im trying to do is attach two movie clips from a class.
PHP Code:
class work {
public function work() {
_root.attachMovie("work", "tri", 0);
_root.tri._x = 0;
_root.tri._y = 0;
}
public function button() {
_root.attachMovie("button", "but1", 1);
_root.but1._x = 520;
_root.but1._y = 80;
}
}
the first method works but the second one does nothing can anyone please help thanks
Can I Attach A Document Class At Runtime?
i want to load a swf into a blank document, and force the SWF to a have a document class, and i don't want to set the document class inside the file FLA, before composing it
Attach A MC To An Object Assigned To Class By Name
I have created an Actionscript 2.0 class and using the convention:
ActionScript Code:
var someVar=new menuItem(blah blah blah);
I have great success, but when I try:
ActionScript Code:
var someVar:menuItem = new menuItem(blah blah blah);
and then look at my MovieExplorer tab, I have multiple sets of recursive elements. Why?
Also, when I drop a MovieClip from the library that has been assigned to the custom AS2.0 class that I have defined, is there any way for the class to find out the objects name if it was added manually to the timeline?
I have created these custom icons that have linkageID's related to the name of their parent clip. (i.e. biography.lbl) is a LinkageID for the biography icon. It works great when I use AS2.0 in the MovieClip to attach the new menuItem's MovieClip to the stage, but when I add it manually, I can't figure out how to make the class constructor or any method to look at the object's name and then attach a clip to itself based on its name?
Let me know if I have you completley lost. I can try to explain it another way, maybe. Thanks in advance for all of your help.
Rowdy
Attach A Moveclip The Pass To Class File
I have an application that loops over an object, which contains the properties of many different items. The items will then need to display on the stage. Each item has a xcord and ycord values. I have a class file, which i need to pass the values to. The Class file will then place the object on the stage for each item depending on the co-ordinates passed.
The problem i'm having is that i cannot send though the movieclip (which is attached a new instance name for each item) to the class. If i only have one item and hard code the movie clip value it works fine.
PHP Code:
var xcord:Number;
var ycord:Number;
for (var i:Number = 0; i<unitObj.length; i++) {
xcord = unitObj[i].xcord;
ycord = unitObj[i].ycord;
this.attachMovie("mcCircle", "mc" + i, depth++);
phMC = "mc" + i;
var unitItem = new unit(phMC, xcord, ycord);
}
Here is the snippet from the class file:
PHP Code:
class test.com.unit{
private var phMC:MovieClip;
private var xcord:Number;
private var ycord:Number;
//constructor function
function unit(phMC,
xcord,
ycord){
phMC._x = longitude;
phMC._y = latitude;
}
}
Thanks
Attach Component To Mc That Is Target Of Scrollpane, Possible Or Not?
Hi,
I can't get the following working so I wonder, is it at all possible?
What is wrong with the last line in function PutComponentInScrollPane
CODE
function PutScrollPaneOnStage () {
_root.ScrollPaneContainer.attachMovie("FScrollPane Symbol","ScrollPaneName",0);
_root.ScrollPaneContainer.ScrollPaneName.setVScrol l(true);
_root.ScrollPaneContainer.ScrollPaneName.setScroll Content("EmptyItemsContainer");
setProperty("_root.ScrollPaneContainer.ScrollPaneN ame",_y,20);
}
function PutComponentInScrollPane() {
_root.attachMovie("FCheckBoxSymbol","CheckBoxName0 ",1);
_root.ScrollPaneContainer.attachMovie("FCheckBoxSy mbol","CheckBoxName1",1);
_root.ScrollPaneContainer.ScrollPaneName.attachMov ie("FCheckBoxSymbol","CheckBoxName2",1);
_root.ScrollPaneContainer.ScrollPaneName.EmptyItem sContainer.attachMovie("FCheckBoxSymbol","CheckBox Name3",level);
}
PutScrollPaneOnStage();
PutComponentInScrollPane();
ENDCODE
setting the various lines to coment in the last function shows that I can't attach a component to the movie that is the target for my scrollpane.
I can attach the component to the scrollpane (3th line) bud than it doesn't scroll.
So either I am doing something wrong or what I want is not possible?
Attach Controller To FLV MediaDisplay Component
Hello,
I'm using Flash MX 2004 Pro and have used the MediaDisplay component to stream a flv clip. I'm not keen on using the MediaPlayback component because it won't let me change its appearance and I was the design to fit in with the rest of my movie.
I would ideally like to use the import_video.fla controller which comes as part of the samples with Flash MX (attached). Would anybody be able to tell me the code which will attach this controller to my MediaDisplay component. I've been looking everywhere on the web and can't find an answer I understand! I'm still very new to all this so an explanation in simple language would help me!
Cheers.
Rachel
Scrollbar (MX Component) Won't Attach/resize . .
help! I've gotten the text box to work properly, and it's up and running . . . but I need to add a scrollbox. I've gone thru the tutorial and done it successfully, but when I try to do the exact same thing in my 'real' file . . . the scroller won't attach to the textbox and resize (the way it did in the tutorial). I've gone over the parameters etc a million times and I don't quite understand why it ain't workin' . . .
any help would be greatly appreciated.
http://www.rongilcreast.com/Test_Site/main.html
page w/ text loaded, but no scroller
http://www.rongilcreast.com/Test_Site/main.fla
flash file
thanks in advance . . .
ps. Alternatively, I've created a new movie (scrollbox.swf) that only contains the textbox and scroller, and have gotten it to work properly . . . but don't know how to set up the main.fla file to load the movie into it . . . any help with that avenue of approach would be appreciated as well . . .
http://www.rongilcreast.com/Test_Site/scrollbox.fla
http://www.rongilcreast.com/Test_Site/scrollbox.swf
Attach Controller To FLV MediaDisplay Component
Hello,
I'm using Flash MX 2004 Pro and have used the MediaDisplay component to stream a flv clip. I'm not keen on using the MediaPlayback component because it won't let me change its appearance and I was the design to fit in with the rest of my movie.
I would ideally like to use the import_video.fla controller which comes as part of the samples with Flash MX (attached). Would anybody be able to tell me the code which will attach this controller to my MediaDisplay component. I've been looking everywhere on the web and can't find an answer I understand! I'm still very new to all this so an explanation in simple language would help me!
Cheers.
Rachel
Attach A MovieClip To A Window Component
Hi Guys,
I'm trying to attach my MovieClip 'Test' to my Window Component 'aboutusWindow'. However no matter how many variations I try or values I tweak nothing seems to work.
The Windows is created by the code and destroyed by the code, I was wondering if anybody could help me.
Thank you.
- Anthony
Attach Check Boxes In Component Table
I am trying to modify this table component that I have downloaded..
I want to add another column for the checkboxes where it will be in each row....
Can anyone help me what should i modify/add into the script for the checkboxes??
I have attach a zip file on the table example...
Simple Question - Attach Component To Given Level
I'll keep it short.
How do I dynamically attach a component (such as a Button) to a level other than the one I am on with actionscript at runtime?
attachMovie only has a depth argument, not a level, so that won't work.
Attach Custom Scrollbar To List Component
how can i attach a scrollbar (other than macromedia ui scrollbar) to the macromedia list component.
I am using the ulimtate scrollbar, when attached to the list comp it just scroll the entire list box, no the actual content
http://briancthomas.com/shaved/scrollbar/new/
mockup of effect i am try to achieve
http://briancthomas.com/shaved/scrollbar/
Static Method To Attach A Clip To A Stage And Assign It A Class?
OK thats a long title, so here's what I want to do. C# has a class called MessageBox with a method called Show. I want that same functionality in Flash. So I have a class called MessageBox with a private constructor and a static method called "show." How can I make my MessageBox movieclip appear on the stage when I call show? I know I can just drag it out on the stage and make it visible when I need it, but this is more of an exercise of "is it possible?" Any ideas?
ActionScript Code:
import net.imageplant.Delegate;
class com.galvanicprinting.custombcard.MessageBox extends MovieClip
{
private var _txtMessage:TextField;
private var _btnOK:Button;
private function MessageBox(strText:String)
{
_txtMessage.text = strText;
_btnOK.onRelease = Delegate.create(this, onOKRelease);
}
public static function show(strText:String):MessageBox
{
//how can I return a new instance of MessageBox from here, while also attaching the MC from the library?
}
}
Attach A Movie Clip From Library Into The Stage Created By A Class
Hello there!
I'm pretty new to AS3 and OOP.
I want to know how can I attach a movie clip (into the stage from the library) inside a class?
I have this class called 'Map.as' it has a function that adds movieclips (called 'Area' in the library) into the stage. But when I run the movie the movieclips aren't there... I successfully run it in AS2 but is not in OOP way...
And also how can I add a mouse event for these created movieclips?
The created movieclips has 3 frames: frame 1 is for normal event (when the mouse is not over the movieclip), frame 2 is for the mouse over event, frame 3 is for the other mouse over event.
Tried looking everywhere but none of those tutorials can solve my problems..
Please provide an example using these steps:
1. create class (Map.as for example)
2. attach a movieclip into the stage using the created class (2 frames, square on first frame, circle on the second frame)
3. add mouse event listeners (roll over event to display the circle, and roll out event to display the square) to the movieclip
You're help is really appreciated! Thank you very much! ^__^
Dynamic Text From PHP Using LoadVars & CreateTextField & Attach Component Scrollbars
I've been trying to combine the follow two tutorials without much success:
http://www.flashguru.co.uk/000026.php
http://www.macromedia.com/support/fl...t_scrollmx.htm
On frame 1 I attempt to use loadVars() to grab a variable written from a PHP script:
code: loadVarsText = new loadVars();
loadVarsText.load("variables.php?category=news");
loadVarsText.onLoad = function(success) {
if (success) {
trace("done loading");
// make a variable to contain the "content" sent from PHP
textContent = this.content;
} else {
trace("not loaded");
}
};
...The PHP script spits back:
PHP Code:
echo 'content='.rawurlencode($content);
...And on frame 2, I try to build and populate a textbox w/ scrollbar component attached:
code: this.createTextField("myTextField", 1, 35, 75, 230, 270);
myTextField.wordWrap = true;
myTextField.font = "Verdana";
myTextField.textColor = 0x000033;
myTextField.size = 10;
myTextField.html = true;
myTextField.htmlText = textContent;
// attach & set up the scrollbar
initialization = {_targetInstanceName:"myTextField", horizontal:false};
this.attachMovie("FScrollBarSymbol", "myScrollBar", 2, initialization);
myScrollBar._x = (myTextField._width + 35);
myScrollBar._y = 75;
myScrollBar.setSize(myTextField._height);
stop();
No dice, though. Any insight would be overwelmingly appreciated! Thank you kindly
argh|pal|www.dumb-dumb.com
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?
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;
};
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.
Is It Possible To "attach" An Mc To A New Class?
I've set up an as file with the following code (this will be more complex eventually- just testing here)
Code:
package drawing{
import flash.display.MovieClip
import line;
public class Sketch extends MovieClip{
public function Sketch(xIt:Number):void{
var _line:line;
var _lineY:Number=1;
for (var i:Number=0; i<xIt; i++){
_line= new line;
this.addChild(_line);
_line.y= _lineY;
_lineY++;
}}
}
}
What I'd LIKE to do is just swap out mcs in the main timeline: ie: using _line as I would have used an empty mc in AS2. Can I do this?? Thanks in advance.
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?
Dynamically Attaching A Component To Another Components Class
Basically I have a component and a class - in it I want to attach another custom component within it
my classes extend UIObject and have set size, init draw and createchildren in
And in the createchildren method I do this
this inst = createClassObject(myClass, "MyNewComponent", this.getNextHighestDepth());
I only works if second component is a compiled clip.
However repeatingly goes into second components constructor method
Has anyone had experience of attaching a user created component within a component???
Class Files And List Component Variables...
Hey everyone!
Has any of you came across the error:
The class 'List' could not be loaded.
var fileList:List;
I've got a class file and this is just a variable declared at the top as I'm wanting to make the list component named "fileList" accessible and need to declare it.
A solution would be greatly appreciated cos this is for a final year uni assignment due in next week
unless someone wants to send me a media player that has video, audio and images using class files and gets data from xml
Sounds simple but I've got 5 other assignments...
Thanks!!
Dan
Problem On Accessing A Component Class Methods
Hello. I'm developing a component which incorporates standart Button and TextInput components. To handle those components events, for example "click" or "change" event, i'm creating an object in main class, and creating functions attached to that object. When coding in this object scope, "this" statement for main class becoming unaccessible and pointing to current object context. Is there a way to access class dynamic methods or variables from sub-object context? Example:
class something extends UIComponent {
...
private var btnOk:Button;
private var btnOkEvent:Object;
public function something() {
...
}
public function init() {
btnOkEvent.click = function(objEv) {
//In this context "this" statement does not point to
//something class. I mean i couldn't call beginDraw()
//method from here.
//(I know, if beginDraw method begins with static
//keyword, i can call it like something.beginDraw() )
}
btnOk = Create("Button"); //Sample
btnOk.addEventListener(btnOkEvent);
}
private function beginDraw() {
...
}
/*
I know, i can use class it self with event-name functions to handle
other components events but there must be an another way.
public function init() {
...
btnOk.addEventListener(this);
}
private function click(objEv) {
...
}
*/
}
This is a general question/problem for me. Perhaps it has a very simple answer, but i don't know. Is there a way? If so, how? Please help!
|