Referring To A Class Dynamically
I need to create a new instance of a class. I have the name of the class stored as a string, but how do I instantiate the class!? I should use the array access i.e.
var className:String = "MyClass"; var myInstance = new myPackage[className]();
but as you can see, I have to hardcode the package name, which in my case doesn't work. Another unclarity regarding the same problem is, wether I can type a variable dynamically i.e.
var className:String = "MyClass"; var myInstance:[className] = new myPackage[className]();
Is there a neat way to solve this dynamic referring, or do I need to start building work-arounds...
Cheers!
FlashKit > Flash Help > Flash ActionScript
Posted on: 04-28-2004, 10:20 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Referring To Dynamically Created Mc's
Hi,
I have the following code:
code:
for (i=1; i<50; i++) {
duplicateMovieClip(gLetter_mc, "gLetter_mc" + i, i);
["gLetter_mc" + i]_x = (Math.random() * 400);
duplicateMovieClip(aLetter_mc, "aLetter_mc" + i, 50+i);
["aLetter_mc" + i]_x = (Math.random() * 400);
}
I know it is not worded right, as it returns an error. How exactly should I refer to a dynamically created movie clip in order to change it's _x position?
TIA,
aaroneousmonk
Referring To A Dynamically Name Movieclip ?
Hi there
I'm trying to refer to a dynamically named movieclip within a dynamically named movieclip.
Does anyone know how to do this?
_root["mc"+(counter1)].mc2 = "testing"; works as i'm only referencing through one dynamically named movieclip. But for two, i'm getting an error.
here's my code so far:
_root["mc"+(counter1)].["mc2"+(counter2)] = "testing";
This obviously is creating an error... any suggestions?
Thanks
Referring To Variables Dynamically
Hi
I'm just starting out with action script so forgive me if any of this is obvious.
I am currently working on a simple logic puzzle involving a punch card.
Currently I have a graphic for the card which contains six buttons, for the punch holes.
What I want to do is have a pre set combination of punches which will solve the puzzle.
To this end I have created six variables for the current status (punched or unpunched) of each button, and six varriables containing the correct status of each button.
here is the solution I have been working on
code:
function punch (buttonNo) {
trace ("hole " + buttonNo + "was punched");
if ("punch" + buttonNo + "Status" == true) {
set("punch" + buttonNo + "Status", false);
} else {
set("punch" + buttonNo + "Status", true);
}
}
as you can see what I have done is to define a function which simply coverts between true and false, the problem being the way i reference my varriables.
The status variables are named punch1Status thru punch6Status, so in my function's 'if' and 'else' statments, I have attempted to reference them dynamically by cocatenating the buttonNo (a property which contains the number of the button punched) with the text elements from my varriable name.
This method seems to work when using the set() function but what I need is away of using this dynamic reference format without altering the value of the varriable.
Being a begginner I would appreciate any feedback, please let me know if I'm going about this completely the wrong way.
Many thanks in advance
P.S.
As I write it has just occurred to me that it would make sense if there was an operator which would simply convert between true and false, can anyone tell me what that operator might be?
Dynamically Referring To Clips?
Okay! I'm having a thing where there are multiple clips generated with duplicateMC, that are all named circles1,circles2, etc. Then, I am using another for statement to try to referr to the circles in a hitTest. How would I do this?
(x is the for variable)
hitTest("circles"+x.toString())
that won't work
So how is it done?
Referring To A Class?
hello,
how do you refer to a class by name? I know how to get the class to do all sorts of stuff from inside the class constructor using the keyword "this". However how do you get the entire class to respond to a button press as the keyword "this" when on a button event handler refers to clip containing the button? right?
Referring To A Dynamically Named Movieclip?
Hi there
I'm trying to refer to a dynamically named movieclip within a dynamically named movieclip.
Does anyone know how to do this?
_root["mc"+(counter1)].mc2 = "testing"; works as i'm only referencing through one dynamically named movieclip. But for two, i'm getting an error.
here's my code so far:
_root["mc"+(counter1)].["mc2"+(counter2)] = "testing";
This obviously is creating an error... any suggestions?
Thanks
Referring From Class To Scene
I have constructed a rough game which is about catching 2 kinds of objects.
An object that increase score, and one that increases your teachers rage(its a game that will be about our school).
My problem lies in makin the Rage-bar, health-bar and score-increase when an object is caught.
If someone has a moment to take a look at it, it would be much appreciated.
I believe my main problem is that i can not refer the class to objects on the scene.
I uploaded the files to make it easier for you to point out my problem
http://www.casperholden.dk/files/flashkit.rar/
Thanks in advance.
Referring From Class To Scene
I have constructed a rough game which is about catching 2 kinds of objects.
An object that increase score, and one that increases your teachers rage(its a game that will be about our school).
My problem lies in makin the Rage-bar, health-bar and score-increase when an object is caught.
If someone has a moment to take a look at it, it would be much appreciated.
I believe my main problem is that i can not refer the class to objects on the scene.
I uploaded the files to make it easier for you to point out my problem
http://www.casperholden.dk/files/flashkit.rar (.rar)
http://www.casperholden.dk/files/flashkit.zip (.zip)
Thanks in advance.
Referring To Dynamically Generated Movie Clip
Hey guys,
Here's my problem: I've got a number of dynamically generated instances of movie clips on my Stage, each with a name of the form "grid_X" where X is an integer. How do I refer to a particular instance dynamically? (e.g. in a for-loop, where the index is X)
JavaScript allows for this sort of syntax: document.getElementById("grid_" + i).whatever...
Does ActionScript have something similar? Much appreciated!! :-)
Ben
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?
Referring To Dynamically Named Movie Clips In Actionscript
Hi there
Basically, I'm really confused about the syntax for referring to a movie clip which you've created in a for loop, and named accordingly, like so:
for(i = 1; i < 8; i++){
j = "holder"+i;
createEmptyMovieClip(instanceName=j,i);
loadMovie(i+".png",j);
j._x = 30 + (i*80);
}
So, that all works fine, except for the last line :
j._x = 30 + (i*80);
Obviously I want to set each mc's x to a different position, but I guess I must just not be referring to it correctly? Which is weird, because the loadMovie(i... thing works fine. What I'm doing at the moment is setting it manually after the for loop but that's so dumb when I could cut down 14 lines of code to 2 lines (I'm doing both the x and y co-ords).
Any help appreciated!
[F8] Instantiate Class Dynamically
My problem is instantiating a class. The class should start after a succesful load to a webservice. However I cannot figure out how to instantiate my class.
My idea was to create an array on the keyframe, then make an element of that array my class.
*NOTE; I have already done the load functions for the web service. It does load properly, and I don't get any error messages.
Code:
import mx.services.WebService;
import classes.*;
//
var manage_ws:WebService = new WebService ([link]);
//
var classAr = new Array(0);
//
load_list = manage_ws.GetSlidesForSlideType (localID, sID[1]);
//
load_list.onLoad = function (list) {
var className = list[0].SwfFileName.split (".swf");
var cName = className[0];
//
startClass (cName, list);
};
//
load_list.onFault = function (e) {
trace ("failed: " + e.faultstring);
};
}
function startClass (myClassName, slideAr) {
//
classAr[0] = new [myClassName] (slideAr);
}
This is my class below, just a constructor that trace for testing
Code:
class top5 {
public function top5 (listOfSlides){
trace("I was loaded");
}
}
Is there a way to instantiate a class in an array I've already declared, then delete it and make a new class in the same element?
or am I making this way too complicated...
Thanks
- Kiwi
Dynamically Assign Class
hi,
I have a class that extends MovieClip and simply loads a sound, adds an event listener for MouseEvent.CLICK to play the sound.
For one reason or another I wanted to layout a number of movieclips on the stage and then assign this class to them
the contructor looks something like this
public function soundItem() {
useHandCursor = true
buttonMode = true
addEventListener(MouseEvent.CLICK, playSound);
}
I have another method to load the sound and that works fine
public function setSound(url:String):void {
trace("setSound"+url)
_URL = url
_soundLoaded = false
var request:URLRequest = new URLRequest(_URL);
sound.addEventListener(Event.COMPLETE, completeHandler);
sound.addEventListener(Event.ID3, id3Handler);
sound.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
sound.addEventListener(ProgressEvent.PROGRESS, progressHandler);
sound.load(request);
}
In the parent class I am assinging the class to the instance on stage
soundItem0 = new soundItem();
soundItem0.setSound(soundList[0].soundItem)
the sound is loading fine but the listener gives me nothing??
can anyone help?
cheers
Dynamically Initiating A Class
Is it possible to dynamically initiate a class in AS2? The failed code below will hopefully highlight what I am trying to do.
var currentClass = “Ball”;
var myBall = new [currentClass]();
trace(myBall);//undefined
Dynamically Calling A Certain Class
Hey all,
So I have some animated charts I have done up. They live in my library and are linked with the names; "chart1", "chart2", "chart3." If I want to add one of them to the stage based on a selection by a user, how can I create a dynamic name call to the class to add them. Instead of hard coding them, I want to insert the number into the function. For example.
function createNewChart(myChart){
var newChart = new (this["chart"+myChart])()
addChild(newChart);
}
Of course that doesn't work, so I am looking for the syntax to make it work. Ideas?
- B
Dynamically Creating Class's
Hi,
Recently I've been investigating some open source code as a learning exercise. There are one or two things about it that i'm uncertain about so I thought Id ask here.
Im curious to know if the attached code is used to dynamically create a class named "wavesound"?
Also, when I'm running the code I get an error that says
"TypeError: Error #2023: Class wavesound$ must inherit from Sprite to link to the root."
If i'm right about the code dynamically creating a class how can I get that class to inherit from Sprite?
Any assitance in improving my understanding on this is greatly appreciated!
Thanks,
-dub
Attach Code
var SymbolClass:Class =loader.contentLoaderInfo.applicationDomain.getDefinition("de.benz.wavesound") as Class;
Dynamically Creating A Class
Version: Flash CS4, AS3
Hi - is it possible to turn a given sprite into a Class with a given string as its name?
The resulting class should then be available under that name in the current domain's definitions.
ie.
createClass(someSprite, "someName");
....
var someClass:Class = getDefinitionByName("someName") as Class;
Thanks,
Rick
How To Dynamically Iterate Through Class Names
hi there,
i am finally doing the transition to AS3...
to do that i am trying to convert an old as1 project.
in this project i have 88 sounds with the linkage SND_0,SND_1,... to SND_87 in my library.
now in as1 / as2
i would do the following to create a sound object for each sound:
Code:
all_sounds={};
for (var i =0;i<88;i++){
all_sounds["snd_ob"+i]=new Sound();
all_sounds["snd_ob"+i].attachSound("SND_"+i)
}
as i understand it in AS3 i would have to code:
Code:
var snd0:SND_0=new SND_0()
and there is of course now way i can loop through that like:
Code:
for (var i =0;i<88;i++){
var "snd"+i:"SND_"+i=new "SND_"+i()
}
so what is the solution for doing something like this in AS3?
thanks a lot!
Dynamically Pass BmpData To A Class
Hello,
I want to pass a bitmapdata into a class here is how I proceed (summurized, of course)
Code:
public var NormalSheet:BitmapData;
//..here i load sprites "Sprites0" from an external swf..//
var Normal:Class = Class( domaineApplication.getDefinition("Sprites0"));
//Instancing the sheet
NormalSheet =new Normal(0,0);
//..later I pass the bitmapdata as an object into a class
myClass.setSheet(NormalSheet);
It works allright,
now I'd like to pass dynamically the name of the bitmapData like this:
Code:
var Reference = getDefinitionByName("NormalSheet");
//WRONG : here I got "NormalSheet var is undefined")
myClass.setSheet(NormalSheet);
how can I dynamically pass the bmpData ?
Note that unlike this exemple, my code is into multiple function into the same class
Loading Package Class Dynamically
Hey all,
I have a problem in my hands :/
Imagine you want to create a new class instance from string, say defined by a CMS. Example:
Code:
var dynObj = new ["classes.MyClass"]();
This doesn't work, but this does:
Code:
var dynObj:MyClass = new ["classes.MyClass"]();
I guess flash only loads hardcoded class definitions?
Any ideas?
Best,
Marius
Class For Dynamically Created Gears
I'm trying to create a class that will accept a number and a movieclip as parameters and create a gear that will be displayed and is movable and rotatable on the stage. I have a symbol that is a single tooth of the gear which is exported. The class should create a gear based on the number of teeth passed to it (first parameter) by duplicating and manipulating the "tooth" symbol passed to it (second parameter). It's been a long time since I tackled any actionscript coding and would appreciate any advise. I hope I've explained myself properly.
Creating Class Instances Dynamically
I'm working on a soundboard application in AS3 and I have imported over 50 sounds into Flash and every single one has their own Linkage Class name. The problem is, how to create an instance of each sound dynamically?
Let's say that the Class names are sound1, sound2, etc. Using loop and calling new sound + i (where "i" is the number) doesn't seem to work, but flash throws an error: "Instantiation attempted on a non-constructor". Is there a way to convert Class name-strings into some sort of constructor?
OR is there easier/other way to create instances of sounds with AS?
How Do You Dynamically Call A Class (using Vars) In AS3
Hi all,
Let's say I have two classes :
Code:
package {
public class B1 {
function B1() {
trace("CLASS B1 INSTANTIATED");
}
}
}
Code:
package {
public class B2 {
function B2() {
trace("CLASS B2 INSTANTIATED");
}
}
}
Now in my main movie, I want to create an instance of one of these classes, but I wish to do so dynamically, by referring to the name of the class in a variable, if you catch my drift. So let's say I have an array with the names of the classes :
Code:
var number = 1;
var classname = "B"+number;
var newinstance = new classname;
How can this be achieved ? I get this error if I define classname as a class:
Code:
TypeError: Error #1034: Type Coercion failed: cannot convert "B1" to Class.
at classtest_fla::MainTimeline/classtest_fla::frame1()
Dynamically Associate A Movieclip With A Class
To manually associate a movieclip with a class, you would have the Symbol’s Linkage set to the class. I could do this if there is no other option but it would be cumbersome to attach ( attachMovie() ) several empty movieclips to the stage since the instance will be dynamically built.
There is an Object.registerClass() that seems to do the job, however I haven’t tested it yet. Perhaps this is the answer but I am hoping someone can tell me if there are any other options (perhaps OO) for doing this.
Dynamically Instantiate Custom Class
A: The Problem
1) I have an array of values formated as such [1,0,5,1,7,1,1,0...]
2) I have a series of custom classes named Tile0, Tile1, Tile2...
3) I have a var classString that is a concatenation of the string "Tile" with whatever value I am pulling from the index.
4) I wish to instantiate one of the classes from 2) with the dynamically created string in 3)
B: Tested Solutions
1) If I hard code the class names from A:2 they instantiate correctly, so I know they are working
2) The problem is strictly related to instantiating a class from a variable
3) I did a search here last night and returned one thread on the subject (link), but was not able to successfully implement that technique do to lack of details.
Does anyone know how to do this??
Assigning Document Class Dynamically
I was wondering if you could assign a document class to a swf file dynamically? I realize you could just pass a reference of the swf once it's loaded to the class after instantiating the class using "getDefinitionByName", but I was wondering if there was a way to assign a class to a swf to be used as the document class at runtime. Any ideas would be much appreciated.
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???
Referencing Dynamically Created Instances Of Class
I've looked up several links but can't figure out why I can't access my dynamically created instances of class in as3... my code is...
Code:
var textPara:textPara1 = new textPara1();
content.addChild(textPara)
textPara.name = "bab"
var maxIndex:Number = content.numChildren - 1;
content.setChildIndex(content.bab as MovieClip, maxIndex);
content.bab.y = 50;
content.bab.x = 500
;
It adds an instance of the "textPara1" class (which I've put in the variable placeholder "textPara") to the display list of the "content" movieclip...
but despite assigning the new instance the name "bab", I can't seem to be able to access it (i.e. when i want to set the x and y position).
I thought it might have something to do with using array [i.e. square brackets] syntax, but already tried that to no avail.
My other thought was maybe I have to write in some sort of code that makes sure the instance has loaded to the stage/display list first and then write and function which references only after that has happened... but I could be talking nonsense!
Please please help. Any thoughts/links very very appreciated.
Cheers.
Dynamically Attaching Objects From A Custom Class...
I think the title is a good descriptor...
I have a custom class that extends the MovieClip class and I want to be able to add instances of it to the stage at runtime...
If I were using the MovieClip class, I'd just use this.attachMovie(). The problem is that attachMovie() uses the linkage ID from the library so I dont think I can create a new instance of my custom class and attach it to the stage with that command.
I have also set the actionScript 2.0 class in the linkage properties box to be the name of my custom class but that still doesn't seem to allow me use attachMovie() and have access to the custom classes attrributes or functions.
Any ideas?
Cheers.
Dynamically Playing A Flv Player In Swf File Using Class
I am an AS3 nubie student in an advanced Flash AS3 course, and our class has a project that we are supposed to research and find the answer to.
The project: How to place a FLVPlayer into a swf file dynamically, so that there is nothing on the stage and the player is being instantiated with code in a separate as. file. We are also supposed to use a package to do this.
In the help documentation of Video Class Package in Flash CS3 they introduce this an idea similar to this, citing an example with an FLVPlayback component placed on the stage at 0:0:
package
{
import fl.video.FLVPlayback;
import flash.display.Sprite;
public class FLVPlaybackExample extends Sprite {
private var videoPath:String = "_yourvideo.flv";
public function FLVPlaybackExample() {
player.source = videoPath;
player.skinBackgroundColor = 0x666666;
player.skinBackgroundAlpha = 0.5;
}
}
}
This seems simple enough. You just make sure your class is name "FLVPlaybackExample" or whatever class name you chose, and make sure to implement it in the public class and public/private function using the same name(your class name, in this example it is FLVPlaybackExample). So I did this. I also named my as. and fla. file the same name....FLVPlaybackExample.
The issue:
The example tells you to put an FLV player component on the stage at 0:0. Then the above code should call up an instance of it to control it with actionscript....I am guessing.
The question is, how do you get this player off of the stage using the addChild method and call out the dimensions to put a player in your swf file "dynamically"? I tried removing the player from the stage while leaving it in the library, and tried the addChild method for instantiating the player in my swf. The result: It didn't work. I don't remember what the errors all were. What I do know is that I "broke it".
How would one get an FLVPlayer off of the stage visually.... but put it in a swf dynamically using a class package? When I checked the linkage of my FLVPlayback component, the class is "fl.video.FLVPlayback" for the player, and the class box is grayed out....implying that this class in not "writable"? or "editable"?....not sure, but that is usually what a "grayed-out" box means.
Our instructor wants nothing on the stage, we need a separate as. file, and everything has to be in a class package, i.e. the document class. We have been encouraged to use forums to research and find the answer on how to do this. So far, I am not having much luck.
It there a modification to this example that might do this very thing? I never found anything in your forums about it. I am guessing that a dynamic FLV player is fairly standard practice in the coding world. Without using XML, is there an AS3 way to set one of these up? It doesn't have to go into a web application. It is just supposed to play an FLV file from a local folder.
TommyB
AS2.0 Dynamically Load Jpg Into MovieClip As Class Instance
I'm working on a photo-sharing demo using AS2.0, and I have a question that I would very much appreciate help with. I would like to dynamically load photos (stored as jpgs in the .fla's local directory) into MovieClips, and apply a class instance to them. Currently, for debugging, I've imported jpgs to the Stage, converted them to MovieClips, and then accessed their linkage properties, setting them to the class I need them to implement. But for the final application all of this will have to be done with code.
I know how to dynamically load the jpg into a MovieClip using loadImage(), and I know how to create a MovieClip that is an instance of a class by using attachMovie() with a library symbol and the class name. How do I combine the two? Is there a way to access the linkage properties of a MovieClip dynamically?
Thanks!
How Do I Dynamically Create An Instance Of Class Which Extends MovieClass
I have a class which extends the MovieClip Class. I know I can create a symbol in the library, create an instance of it, give a name and manually set AS linkage to my extended class - is there a way to do it without creating a symbol at all. I.e. create an empty movie clip and then just cast it to my class that extends Movie clips?
Thanks
Leonid
Dynamically Assigning Code To An Object Inside A Class. Which This Is This?
EDIT: Sorry, this is AS2, Flash8
Okay, I have a class named ship that I want to use to create some temporary movieclips and give them some onRelease code. I would like to pass to the movieclip onRelease code, the class object that created the code... but I am not sure if 'this' will be evaluated to be the movieclip that the onRelease code is assigned to, or the class object that assigned that code...
Does this make ANY sense? How about some pseudo code...
PHP Code:
class Ship extends MovieClip {
private var maxhandsize = 3
private var cardsinhand:String = "" //comma deliminated listing of cards belonging to this player.
public function discard(){
var inhandarray = cardsinhand.split(",");
if (maxhandsize > inhandarray.length) {
for (i in inhandarray) {
this["tempcard" + i] = attachMovie(a card from the library)
this["tempcard" + i].onRelease = function([b]this[/b]){
//code for discarding cards that are clicked on.
//code for removing all these cards once inhand array is under maxhandsize again
//this code needs to know WHICH ship called it so it can call a method for this ship to continue onto the next steps.
}
}
}
}
The this up above in the onRelease line.... will that mean the ship object or the tempcard+i instance of the card from the library?
What about addition references to 'this' inside the {} brackets of the onRelease funtion? Are THOSE this's the ship or the card movieclip?
Creating Dynamically-named Variables Inside A Class
I'd like to have a class that creates the necessary amount of variables when it's instantiated according to data passed to its constructor. This means that, in the class definition, I cannot declare any of these - they wouldn't exist before the class is used. The situation is just in creating page variables to then set from false to true when completed. I would just need to create internal booleans named page#, and set them to false (page0 = false, page1 = false, etc.).
Of course, when trying this, I get an error "Cannot create property..." - so how is this properly done?
Attach Code
package com.course {
dynamic public class CompletedPages {
public function CompletedPages(myXMLFile:XML){
// create as many page# variables as there are pages in the XML file
for (var i:int=0; i<courseXML.page.length(); i++) {
this["page"+i] = false;
}
}
}
Edited: 12/20/2007 at 02:23:21 PM by srlindberg
Dynamically Creating Instance Of Extended MovieClip Class
Hi all,
I have recently started out with flash oop concepts and was wondering how to do create an instance of an extended movie class without dragging and dropping the clip from the library ....
I have figured out this method..
for(i = 0;i<100;i++)
{var mc:MovieClip = attachMovie("ball","dasd"+i,_root.getNextHighestDe pth());
mc._x = Math.random() * 600;
mc._y = Math.random() * 600;
}
but this way I cant pass arguments to the constructor function of the ball class...
any help would be highly appreciated
regards
Sarvagya
[F8]AS2.0 Dynamically Load Jpg Into MovieClip And Apply Class Instance
I'm working on a photo-sharing demo using AS2.0, and I have a question that I would very much appreciate help with. I would like to dynamically load photos (stored as jpgs in the .fla's local directory) into MovieClips, and apply a class instance to them. Currently, for debugging, I've imported jpgs to the Stage, converted them to MovieClips, and then accessed their linkage properties, setting them to the class I need them to implement. But for the final application all of this will have to be done with code.
I know how to dynamically load the jpg into a MovieClip using loadImage(), and I know how to create a MovieClip that is an instance of a class by using attachMovie() with a library symbol and the class name. How do I combine the two? Is there a way to access the linkage properties of a MovieClip dynamically?
Thanks!
How Do I Dynamically Create An Instance Of Class Which Extends MovieClass
I have a class which extends the MovieClip Class. I know I can create a symbol in the library, create an instance of it, give a name and manually set AS linkage to my extended class - is there a way to do it without creating a symbol at all. I.e. create an empty movie clip and then just cast it to my class that extends Movie clips?
Thanks Leonid
Adding Dynamically A Getter Setter Function To A Dynamic Class
Does someone know how to add getter and setter methods dynamically to a dynamic class ?
Code:
function get foo():Object {return _foo;}
function set foo(Object f) {_foo=f;}
For example I would like to do something like :
Code:
var mc:MovieClip=new MovieClip();
mc.get foo=function() {...}
mc.set foo=function(...) {...}
But it doesn't work...
[CS3/FP8/AS2] Unable To Reach Dynamic Text Within Dynamically Created Mc From Class
Hi!
In my project there will be a number of "papers" showing different text but (apart from a few minor things) all "papers" will work in the same way, because of this I have made a class "infoPaper" and place all my clips on the stage dynamically like this:
PHP Code:
this.attachMovie("mcInfoPaper", "infoPaper_1", 10, {_x:60,_y:60}).init("some test text",100);
"mcInfoPaper" is a white paper background, a dynamic text-field named "txtContent" and a few buttons (close button etc). My class contains an init function where I would like to set the text and scaling (and later a few other things) through passing parameters.
This is my class:
PHP Code:
class infoPaper extends MovieClip {
function infoPaper(){
// no arguments passed
}
public function init(tcontent:String, pscale:Number):infoPaper{
// use values as you would in the constructor
this.txtContent.text = tcontent;
this._xscale = pscale;
this._yscale = pscale;
return this;
}
}
All of this works nicely apart from this:
PHP Code:
this.txtContent.text = tcontent;
where I get the following error:
Code:
There is no property with the name 'txtContent'.
The instance names etc seems to be correct as I can reach txtContent from outside the class, by setting the value after the creation of the movieclip instance, like this:
PHP Code:
this.attachMovie("mcInfoPaper", "infoPaper_1", 10, {_x:60,_y:60}).init("some test text",100); //this doesn't change the text
this.infoPaper_1.txtContent.text = "this is my test text"; //this changes the text
it's just from within the class I can't get it to work.
Any solutions or ideas why this is?
I'm working in CS but targeting Flash Player 8 using AS2.
Thanks,
Linda
Dynamically Referencing An External Class (not Embedded Movie Clips)
I've seen several posts for how to dynamically attach movie clips from the library, since they become their own classes. This question is how to dynamically refer to external classes.
The example that showed this was:
function createNewChart(myChart:int){
var classRef:Class=getDefinitionByName("chart"+myChart) as Class;
var newChart:*=new classRef();
}
I want to instantiate an external class versus a movieclip, and using this code outright is not the trick - I get an error (Error #1065: Variable MyClass is not defined.) from the following:
var presentationClass:String = classNameFromXmlFile; // MyClass
var classRef:Class = getDefinitionByName(classFromXMLfile) as Class;
var myClassInstance:* = new classRef();
I know that hard-coding the class here does work, so the class itself is fine, as in the following:
var myClassInstance:MyClass = new MyClass();
What is the proper syntax for dynamically doing this?
Referring To Sub Mc
Hi
I have this problem. I am trying to refer to a sub movie clip.
The code goes like this.
_root["nodeText"+j].["node"+j]._width = node_size_x;[as]
the path goes like this but i want "j" to save me haveing to type...
_root.nodeText0.node0._witdth = ....
_root.nodeText1.node1._witdth = ....
_root.nodeText2.node2._witdth = ....
Cheers
Referring To Instances Through A Var?
Does anyone know of a way to refer to instances through a variable name?
i.e., if I have created an instance using
(where var_name = "instancename")
duplicateMovieClip(target, var_name, 1);
But now I want to immediately access the movie clip who's instance name is "instancename" (stored in var_name), but I can't just use var_name.text_name, because the AS will look for a movie clip named "var_name".
I want to name a text box "instancename" in the newly constructed movie clip, also called "instancename". So is there a way to do something like this?:
var_name.text_name = var_name;
^
|
|
do something to this so the compiler 'reads' it as "instancename" instead of "var_name"
Thanks.
Greg
When Referring To _levels
Hey there,
If you've set the level for a movie to be loaded onto as '8', when you want to refer to that level, do you say
code:
8.play()
or do you still have to say
code:
_level8.play();
Just wondering.
Thanks
[F8] Referring To Objects
Hi
I have loaded in a symbol with a linkage name of image using attach movie. It loads in fine, but how do I refer to it to to do things like modify its position etc.
Thanks
sand_monkey
Swf And Referring Domain
Is there a way to find the domain of the page that loads my swf. For example, someone embeds an swf served from my server on their www.myspace.com page. Is there is way for me to determine that the request is coming from myspace.com at runtime?
I have the option of using AS 3 if it provides a solution.
Referring To Functions
I have created a button within a movieclip and the following script appears in the button. This movieclip/button combination is added to the Flash game I am creating programatically:
ActionScript Code:
on (press) {
startDrag(this);
}
on (release) {
stopDrag();
if (eval(this._droptarget) == _root.garbage) {
actions.search_for_coin(this._name);
this.removeMovieClip();
}
}
I am trying to refer to a function that resides in a movieClip called "actions" which is at the root level. I can't seem to get to the "search_for_coin" function. What am I doing wrong?
Swf And Referring Domain
Is there a way to find the domain of the page that loads my swf. For example, someone embeds an swf served from my server on their www.myspace.com page. Is there is way for me to determine that the request is coming from myspace.com at runtime?
Referring A Mc Inside A Mc
i have a parentmc and a childmc.
parentmc.onRelease=function(){
trace("parentmc was clicked");
}
parentmc.childmc.onRelease=function(){
trace("the child was clicked");
}
what can i do to make it work?
Edited: 03/16/2008 at 12:58:38 PM by elic05
Referring To Many Things At Once
Just learning actionscript. (I'm a better programmer than visual artist)
I have a question in 2 parts.
Is it possible to either
refer to all m.c.s at once
or
dynamically (additively) group m.c.s
essentially, I am trying to replicate radiate accretive growth in Flash.
however, I need to add objects dynamically and be able to check the bounds of all objects.
ANy help will be appreciated.
|