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




Manipulating A MovieClip Instance From A Class File



I have as2 code in a class file that is imported into a fla file. I've been trying to manipulate the movieClip instance that I have on the Stage via just the Class file. Example:I have a MovieClip on stage with an instance name of box_mc. I want this movie clip to turn invisble when I click the mouse button on top of it. The key is that I want all mouse press functions to only reside in the Class file and not the fla.The issue I am having is that when I test the movie in Flash and click on the movieClip nothing happens but the test trace() command is run.Any help would be most appreciated!Attach CodeThis is the code I have on layer 1, frame 1 of the fla file:import com.BoxTest;var initBox:BoxTest = new BoxTest(box_mc);This is the code that I have in the *.as file:class com.BoxTest extends MovieClip{public var box:MovieClip;public function BoxTest(box:MovieClip) {this.box = box;invisible();}public function invisible():Void{this.box.onPress = function(){trace('test');this.box._visible = false;}}}Edited: 07/18/2008 at 10:53:03 AM by enzoZero



Adobe > ActionScript 1 and 2
Posted on: 07/18/2008 10:49:45 AM


View Complete Forum Thread with Replies

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

AS2: Manipulating Class/instance Properties? HELP
The mission: create multiple MCs (see the attachment) of a library item (a ball) that is linked with a class. At runtime, if user presses "q", ALL INSTANCES of that ball get bigger, instances get smaller, if user presses "a".

How did i try to solve it: with a for loop i cycle through all the instances and call a instance method to scale the balls.

The question: is there any way of doing this without the for loop?? What can i do to make this process less CPU consuming? Too bad, flash doesen't let (static) class methods to acces instance properties.

Need help!!!
Thank you!

Kekec

Instance Name In MovieClip Class
How can I acess a instance name from a class of a movieclip?

Finding A Instance In A Movieclip With A Class
hi,

In the document Class I've put several buttons in a container, it all works well. These buttons are movieclips in de .fla (linkage). Inside this movieclip there's this accent_mc which is just another movieclip with the instance name: accent_mc. This upAction for all the buttons works also fine, so line 5 and line 8 are doing "the job" (one button jumps to the right).

In line 6 I'm trying to reach the accent to be visible... how come it's not working? ( Error #1123: Filter operator not supported on type Knop1. at Main/upAction()

1. private function upAction (evt:MouseEvent)
2. {
3.for ( var i:int= 0; i < numberButtons ; i++)
4.{
5.container.getChildAt(i).x = 0;
6.container.getChildAt(i).(getChildByName("accent_mc ") as MovieClip).visible = false;
7.}
8.evt.target.x += 10;
9. }

Could anyone help me a bit? Do I have to send more script first?

Thanks a lot!!
Jean-Francois

How To Create An Instance Of Class Extending MovieClip In AS2.0?
In Action Script 2.0, how do you create an instance of a class that extends the MovieClip class and put it on the screen?


So I have a class below that extends MovieClip that simply draws a triangle. How do programmatically create an instance and put it on screen? I tried createClassObject() but that didn't work.

class MyMovieClipClass extends MovieClip
{
// Constructor
function MyMovieClipClass()
{
this.drawMe();
}


// Draw a simple triangle for the heck of it.
private function drawMe():Void
{
this.clear();
this.lineStyle(10, 0xCCCCCC);
this.lineTo(300,0);
this.lineTo(300,200);
this.lineTo(0,0);
}

}

Reference A Custom Class Instance From A Movieclip
Hi there,

I've built a custom class that sets references to movieclips, but I want to reference the class methods from inside them. How can I do that? If I access with "this", it references the movieclip itself, if I reference the method without "this", directly by its name, it doesn't exist. "_parent" doesn't work, too (and I don't think it should...).

Help me, please!!!

Thanks,

Diogo

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!

Dynamic Creating Instance Of Class+movieclip With Arguments
I have extra class functionality (class is called player) i want to link that to a movieclip i have in my library.
so

in the linkage identifier box on properties from the library i have

Player

it all works so far.

the player class will do some things, what i want to know how to do is to get it dynamic on the stage (easy) but with passing arguments.

I tried the following

attachMovie("generic_player","player00",1,{nme:cal vin});

this isnt it though. How can i pass in argument at run time.
obviously

myPlayer:Player=new Player("arg")

does what i want but then has no movie clip on the stage !

any help appreciated, no one ever replies to me! go on help me out.
ta
mojito

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!

Adding Instance To Stage From A Movieclip Linked Class
Hi,
I was trying to add an instance I created in a class to the main
stage, like this:


Code:
var blackD:MovieClip = new blackboardinfo();
Stage.addChild(blackD);
it was working fine, however, after I added preload page, which will now
load everything else as external swf, i began getting this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.

I tried to modify the code to this based on the similar questions i found online


Code:
var mc:MovieClip = new MovieClip();
addChild(mc);
var _stage:Stage = mc.stage;
_stage.addChild(blackD);
I still get the same error, I know it is because "stage", but if I dont use stage, how
can I add an instance on top of everything? thanks.

Manipulating A Duplicated Instance
In the past I have singled ot and manipulated a generated duplicated instance - for example clip3._xscale =150 which owuld result in a single clip being identified amonst the duplicates.

However, in the code below I'm unable to target a clip.

Does anyone know if this may have something to do with usting the Math functions?

for(i=0;i<nrc;i++){
duplicateMovieClip("clip2","orbit"+i,i);

orbit23._xscale=600; // this has no effect????????

mymath = _parent.clip1["orbit"+i]._xscale = 300*Math.cos(Math.PI/-180*nrc*i+Math.PI*cnt*step/300); ///45width,circum

Question About Create Dynamic New Instance Of Typed Movieclip In Class Code.
Hi,

Im having some troubles (driving me crazy.. ) when i try to duplicate typed class movieclip dynamically, the problem its when i use duplicateMovieClip method only to duplicate a mc in runtime, the new instance doesn't have the mc´s original contents(Images, other mc, tx area) neither the contents of the movieclip (like its in the library...) but if i add the attachMovie method doing something similar to duplicate, a line before duplicate, it works , so it makes the copy of contents, but this copy doesn't have the properties and methods included in the class so i can't use it.
-------
This is the code of class Product, to use it in scroll of products that come from a database, every product imported from the db, its created dinamically from a mc loaded in the Library linked to a class who extends of the MovieClip, that i called "Product" class. This is the code ->


Code:

public function loadColection(xml:XML) {

var total:Number = xml.childNodes.length
for (var i:Number = 0; i < total; i++) {
var img_temp = "imagen_" + i;
var id:String = xml.childNodes[i].attributes["id"]
trace (id);
var name:String = xml.childNodes[i].attributes["name"]
var price:String = xml.childNodes[i].attributes["price"]
var imagen:String = xml.childNodes[i].attributes["imagen"]
trace (imagen);
var data:Object = {_x:130 * i, margen:(130 * (total - 1)) + 10};
this.colection.attachMovie("imagen_mc",img_temp,this.colection.getNextHighestDepth(),data);
var mc:MovieClip = this.colection.imagen_mc.duplicateMovieClip(img_temp, this.colection.getNextHighestDepth(), datos);
this.loadImagen(imagen,mc);
}
}
Any suggestions ?

[CS3] Referencing A Movieclip Inside A Movieclip From A Class File
Hello All,

I'm trying to access a movieclip inside another movie clip from a class file that is not attached to either movieclip. For instance, I'm checking hitTests for the avatar the player uses on the game, there are two enemy movieclips. Inside each enemy movieclip is another movie clip that serves as a bounding box (specifically around the mouth of the enemy so it can eat the player). Here is what I have so far that isnt working:


Code:
if (_root['otter']['obbox'].hitTest(this) && touch == false) {
trace("Otter touched Urchin");
gotoAndPlay("hit");
_root['otter'].gotoAndPlay("eat");
touch = true;
}
The class file is for the avatar. On the stage is the otter mc and inside the otter mc is another mc called obbox which is what I'm trying to hitTest against. Needless to say, it doesn't hitTest or trace or play the animation. Is there a way to reference a nested mc? Thanks in advance.

Terror.

Manipulating Class-generated Movieclips
To begin, I have been able to draw rudimentary shapes on the main timeline by importing this class on the main timeline (first frame) and plugging in the requisite parameters



ActionScript Code:
class BoxyRounded extends MovieClip {    var iN:String;    var d:Number;    var lst:Number;    var lsc:String;    var lsa:Number;    var x0:Number;    var y0:Number;    var fcc:String;    var fca:Number;    var w:Number;    var h:Number;    var cs:Number;    public function BoxyRounded(iN, d, lst, lsc, lsa, x0, y0, fcc, fca, w, h, cs) {        _root.createEmptyMovieClip(iN, d);        with (iN) {            lineStyle(lst, lsc, lsa);            moveTo(x0+cs, y0);            beginFill(fcc, fca);            lineTo(x0+w-cs, y0);            curveTo(x0+w, y0, x0+w, y0+cs);            lineTo(x0+w, y0+h-cs);            curveTo(x0+w, y0+h, x0+w-cs, y0+h);            lineTo(x0+cs, y0+h);            curveTo(x0, y0+h, x0, y0+h-cs);            lineTo(x0, y0+cs);            curveTo(x0, y0, x0+cs, y0);            endFill();        }    }}


Once the shapes are drawn I cannot seem to manipulate them on the main timeline to make them move about and alpha up and down. Is there some way to do this?

[BTW, here's the first frame code]

ActionScript Code:
stop();import BoxyRounded;//function BoxyRounded(iN, d, lst, lsc, lsa, x0, y0, fcc, fca, w, h, cs)var box3:BoxyRounded = new BoxyRounded("box3", _root.getNextHighestDepth()+1, 0, "0x00ff00", 0, 0, 0, "0x800000", 100, 50, 250, 100);



When I have created movieclips without actionscript, then attached AS 2 classes to them I can manipulate them. If there is not a way that I can manipulate AS-generated clips on the main timeline, is this doable from within the class?

Thanks for your time.

Attaching A Class Instance That Extends "MovieClip"
Hi,

I would like to know if there's a way to attach movieclips besides empty ones (createEmptyMovieClip), from the library (attachMovie) or external ones (loadMovie).

In my case, I have a class that extends MovieClip. All I want is to attach an instance of that class (created with the new statement), or at least to associate it with an empty movie clip.

I suppose I can always create an empty movie clip and link it to my class, but that limits reusability, as I would always have to have a particular (empty) symbol on the library for this purpose.

Best regards.

Dynamically Defining "new" Instance Of A Class And/or Movieclip
ActionScript Code:
// THIS WORKS
function foo ():void
{
    var newMC:MovieClip = new ClassOf_MC34(); // Statically defining "ClassOf_MC34"
    addChild (newMC);
   
    trace (MovieClip(this.parent).name) // Trace = "MC34"
}



ActionScript Code:
// THIS DOES NOT WORK (but needs to)
function foo ():void
{
    var myMCname:String = MovieClip(this.parent).name;

    var newMC:MovieClip = new ("ClassOf_" + myMCname)(); // Dynamically defining "ClassOf_MC34"
    addChild (newMC);
}


How can I use a dynamic variable when declaring a "new" instance of a class?

Target Movieclip From An AS3 Class File
It seems a stupid question, but, believe me I searched the last 3 days on the net and guess what; thousends of tutorials but none that works for my case!
what i wanna do is simple; I have 3 movie clips on the timeline, but i don't want to control them from the timeline, but, from a separate class (and also control other movieclips/textfield inside them), i have so far, an AS3 file BST_main.as that is the document class of my flash file BST_main.swf and inside my project I have 3 movie clips index_search_bar and index_criteria_bar and index_menu_bar
my class is:

Code:
package {
/*///////////////////////
Importing display class
*///////////////////////
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
/*///////////////////////
Library Movie Clips
*///////////////////////
// Initialising
addMovieFromLibrary(index_search_bar);
addMovieFromLibrary(index_criteria_bar);
addMovieFromLibrary(index_menu_bar);
index_search_bar.y = 100;
believe me I m lost any help?

Pass Coordinates Of Movieclip To Class File?
Hi,

I have an .as class file that contains drag and drop functions for my movieclips. In my main movie I am attaching the clips using attachMovie and assigning ._x and ._y values. Can I pass these coordinates back to the class file? At the moment, if i trace(this._x) in the class file and run the swf, I get 0

Any help would be greatly appreciated.

Adding MovieClip To Stage From As3 Class File
Hello,

Does flash have an equivalent to Flex's Application.application.[insert application method or property here]?

I want to get access from an as3 class file to the main stage. a call to this.root from the stage to the class will not work because I need the root object stage to execute an addChild method. Can you help?


Best,

Richard







Attach Code

package com.custom.text.effects {

// Import the required transition classes.
import flash.display.MovieClip;//import movieclip class
import flash.display.Stage;//import stage access
import flash.text.*;//import all text classes
import fl.transitions.easing.*;//import all easing types
import fl.transitions.*;//import all transitions

public class textEffects {

//create the constructor
public function textEffects(strText:String = "")
{
strText = strText;
}

//declare the properties
public var strText:String;

public function FlyBlind(strText:String) {
// Create a new instance of the Font1 symbol from the document's library.
var myFont:Font = new Trebuchet();

/* Create a new TextFormat object, and set the font property to the myFont
object's fontName property. */
var myFormat:TextFormat = new TextFormat();
myFormat.font = myFont.fontName;
myFormat.size = 24;

/* Create a new TextField object, assign the text format using the
defaultTextFormat property, set the embedFonts property to true, set
the antiAliasType property to "advanced", and rotate the text field. */
var myTextField:TextField = new TextField();

myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.embedFonts = true;
myTextField.antiAliasType = AntiAliasType.ADVANCED;
myTextField.textColor = 0x004B8E;
myTextField.defaultTextFormat = myFormat;
myTextField.text = strText;
myTextField.border = false;
myTextField.x = 115;
myTextField.y = 205;
//myTextField.rotation = 15;

var myMovieClip:MovieClip = new MovieClip();
myMovieClip.addChild(myTextField);

//this line doesn't work yet - the finishing line
// if I try to use the root of myMovieClip I'll get an error because it's not added to the stage
// to have an assigned root value, it must be assigned to the root


{this}.root.addChild(myMovieClip);//an attempt to add myMovieClip to the scene

//list of all possible transitions with example
TransitionManager.start(myMovieClip, {type:Blinds, direction:Transition.IN, duration:2, easing:None.easeNone, numStrips:10, dimension:0});
//TransitionManager.start(myMovieClip, {type:Fade, direction:Transition.IN, duration:9, easing:Strong.easeOut});
TransitionManager.start(myMovieClip, {type:Fly, direction:Transition.IN, duration:3, easing:Elastic.easeOut, startPoint:9});
//TransitionManager.start(myMovieClip, {type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:5, shape:Iris.CIRCLE});
//TransitionManager.start (myMovieClip, {type:Photo, direction:Transition.IN, duration:1, easing:None.easeNone});
//TransitionManager.start(myMovieClip, {type:Rotate, direction:Transition.IN, duration:3, easing:Strong.easeInOut, ccw:false, degrees:720});
//TransitionManager.start(myMovieClip, {type:Squeeze, direction:Transition.IN, duration:2, easing:Elastic.easeOut, dimension:1});
//TransitionManager.start(myMovieClip, {type:Wipe, direction:Transition.IN, duration:2, easing:None.easeNone, startPoint:1});
//TransitionManager.start(myMovieClip, {type:Zoom, direction:Transition.IN, duration:2, easing:Elastic.easeOut});
}
}
}

Access MovieClip From External Class File
I am currently using an external Class file for an instance in my .fla project. It creates an instance of that specific class and has it carry out some functions. I want to access a MovieClip on the stage in the .fla file in the external Class file. How can I do this?

For example, the Class file creates an instance of that class, and I want the x and y coordinates of that instance to be equal to that of let's say circle_mc. Now circle_mc is on the stage of the .fla file, and therefore cannot be accessed. How can I get around this?

Trying To Get Externally Loaded SWF To Act As Movieclip From External Class (.as File
Right I have a problem - when I load a swf and I want to be able to add event listeners to propertys on it I use the code


ActionScript Code:
var headerMovie = MovieClip(loader.content);

Which works fine but what I've have created now is a class to load external SWF's and add them saving me to repeat that code, which works fine for loading the swf but as for the part where I get it to convert to MovieClip (which is what I assume that bit of code does) I'm out of Idea's.

here is the class so far - the error it gives is that it cannot acces the property mloader, I've even declared it outside of the function but to no avail.


ActionScript Code:
package {

    public class PreLoaderSwf3 extends MovieClip  {

        var myTween:Tween;
       


        public var loaderSpin:MovieClip = new Loading_MOV();

        public function PreLoaderSwf3() {
            //stuff for preloader spinner

                        loaderSpin.x = 500;
            loaderSpin.y = 80;
            loaderSpin.alpha = .5;
           
        }
       
       
        public function startLoad(swfAddress) {
            var mLoader:Loader = new Loader();
            var mRequest:URLRequest = new URLRequest(swfAddress);
            mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
            mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
            mLoader.load(mRequest);
            mLoader.x = -400;
            addChild(mLoader);
            //loadEvent.currentTarget.content = MovieClip(mloader.content);
            //mLoader.alpha = .5;
           
        //return convertName;
        }
        function onCompleteHandler(loadEvent:Event) {
            loadEvent.currentTarget.content = MovieClip(mloader.content); //The code giving me trouble
            addChild(loadEvent.currentTarget.content);
            loadEvent.currentTarget.content.alpha = 0;
            this["myTween"] = new Tween(loadEvent.currentTarget.content, "alpha", None.easeInOut, 0, 1, 8, false);
           
       
            removeChild(loaderSpin);
           
            }

       
//stuff for adding spinner loaders and shit all works grand

function onProgressHandler(mProgress:ProgressEvent) {
            var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
            trace(percent);
            addChild(loaderSpin);

        }
    }

}

Manipulating Values Retrieved From A .txt File
How do I load text from a text file into Flash so that I can manipulate the text?

The can only pull it's value into Flash but I cannot use it elsewhere. Please help. Thanks.

[F8] Referencing A Static Class Inside Another Class's Instance
I've got a movie loading into a framework.

This framework has 1 instance of the class main called main.

Inside this class, another class is used, but it is used directly, not as an instance. E.g.:
code:
import com.StaticClass;
class main {
private function UseStaticClass():void {
StaticClass.init();
}
}


From my movie, I can reference the main instance as _root.main. Can I reference StaticClass at all if there's no explicit instance created or it's not assigned to a public variable?

I can't modify main to include getter/setter methods, that's why I ask.

Thanks.

Static Class Variable Referencing Class Instance
I was given the task of writing a class that would send serial requests for xml data, the idea being that the requests could be added while previous requests were still in progress, but the class would queue them and wait for the reply of one request to come back before sending the next.

The way I did this was to create a class instance for each request, and the request itself would be stored in an instance variable, waiting to be sent. A static variable called queue (accessible to all instances) was then given a reference to the instance, and when this reference got to the top of the queue, queue would call the sendRequest() method on that instance.

The reason why I am using one instance per request is so that the replies can be retrieved via the instance, so keeping each request entirely discreet.

Everything works very nicely, but the problem is my IT manager looked at the code and told me that you cannot put a reference to a class instance in a class static variable... and for this reason he has informed my line manager that he has serious reservations about the code, and recommends that it is not incorporated it into the project. However, the code works very well on my local machine and on the testsite, and no-one has experienced any problems with it.

Can someone reassure me here... I can see absolutely nothing wrong with having a class static array hold references to each of the instantiated class instances. And the proof is in the pudding.. it works. Can anyone else see a problem here?

Checking To See If One Instance Of Class Hits Other Instances Of The Same Class?
Hi guys, the idea is similar to Yugop.com JAMPACK 01.

Let's say i have a bunch of balls/cells. I'm having trouble figuring out how to make it so that every other ball bounces off of every other ball.

so in short, it's really one instance being able to check all other instances of the same ball class?

any ideas guys and if you dont know what im talking about, please feel free to state that also.

Loading From Text File And Manipulating Variables
I searched for the answer and have looked through ActionScript dictionary for the answer. I am close, but I need help from a more experienced FLASHer.

I am trying to create a script that will take a movie clip and duplicate it based on what I type in the text document. For instance, within the text document I have:

totalClips=4&

Based on the totalClips variable, I need to duplicate the movie clip that many times. However, when I try to compare the totalClips with the currentClips variable, they never are of an equality.

I have got so far as to figure out that I will somehow have to use parseInt, but after that it just won't work.

Any ideas?

Please let me know if you would like to see the code in its entirity.

Thanks.

Returning The Instance Name Of A Class From Within The Instance
Hi,
I'm trying to do some error reporting in my actionscript.
I have a class MyData which can be instantiated several times over in each project e.g.
var myData1:MyData = new MyData();
var myData2:MyData = new MyData();

In the error reporting I have put statements like
trace("MyData.loadData reports error.... message...");

However, I'd really like it to return the instantiated name, not the generic class name so that I can trace errors to the particular instance that is failing. Does anyone know how to do this? I've tried
trace(this.toString() + " reports error.... message...");
but I just get a name of [object object] which isn't that helpful!

Many thanks!

Delete Instance Of Class From Class' Method
So I have a class called Unit. When I use this class in a .fla file, I create it by saying:

var unit00:Unit = new Unit(...);

So then it creates a gfx representation of the screen for me. I would like to have a method like this:


PHP Code:



public function remove ():Void {   unit_mc.removeMovieClip();   //deleting the gfx representation of the class in the .fla   delete instance of this;   //I want to delete the variable that references the instance of this class} 




So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?

Thanks for any assistance

Accessing Movieclip Instance Within Another Movieclip Instance
Accessing library movieclip instance within another library movieclip instance issues.

I have a movieclip in the Library called menuBar. In the menuBar mc I added two buttons. I want to be able to click on each button to play a video for each corresponding button. When I mouse over the button the pointer turns into the hand, suggesting it recognizes it as a button. But I'm unable to access the button (menuBar.button1 in AS2) in my code, I'm using AS3. Any help would be much appreciated. Thank you for your time.

Instance Of Class Inside Of Different Class
I am trying to make an instance of a class inside of a different class. But I am getting an error:
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 8: A class's instance variables may only be initialized to compile-time constant expressions.
var s1:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 9: A class's instance variables may only be initialized to compile-time constant expressions.
var s2:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 10: A class's instance variables may only be initialized to compile-time constant expressions.
var s3:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 11: A class's instance variables may only be initialized to compile-time constant expressions.
var s4:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 12: A class's instance variables may only be initialized to compile-time constant expressions.
var s5:Step = new Step();

**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 13: A class's instance variables may only be initialized to compile-time constant expressions.
var s6:Step = new Step();

The code for the first class is:
code:
class Event {
var type:String = new String();
var oName:String = new String();
var description:String = new String();
var steps:Number = new Number();
var dueDate:String = new String();
var percent:Number;
var s1:Step = new Step();
var s2:Step = new Step();
var s3:Step = new Step();
var s4:Step = new Step();
var s5:Step = new Step();
var s6:Step = new Step();
function createNewEvent(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11) {
type = d1;
oName = d2;
description = d3;
steps = d4;
dueDate = d5;
percent = 0;
if (steps == 6) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
s5.createNewStep(d10);
s6.createNewStep(d11);
} else if (steps == 5) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
s5.createNewStep(d10);
} else if (steps == 4) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
} else if (steps == 3) {
s1.createNewStep(d6);
s2.createNewStep(d7);
} else if (steps == 2) {
s1.createNewStep(d6);
s2.createNewStep(d7);
} else if (steps == 1) {
s1.createNewStep(d6);
}
}
function showPercent() {
for (var p = 1; p<=steps; p++) {
percent += this["s"+p+""].percent;
}
percent /= steps;
return percent;
}
function done(stepN) {
this["s"+stepN+""].done();
}
function setStepPercent(stepN, p) {
this["s"+stepN+""].setPercent(p);
}
}

The class being loaded is:
code:
class Step{
var completed:Boolean = new Boolean();
var sName:String = new String();
var percent:Number = new Number();
function createNewStep(d1){
completed = false;
sName = d1;
percent = 0;
}
function setPercent(tbs){
percent = tbs;
}
function done(){
completed = true;
percent = 100;
}
}

Please help!!!

How Do I Refer To A Class Instance From Another Class?
Trying to get my head around scope here... I have the following in my root DocumentClass:

var horse1:Horse = new Horse();
var odds:OddsBox = new OddsBox();

From within the Horse class, how can I now refer back to the odds OddsBox instance?

My instinct is to type:
trace(_root.odds);
but that obviously doesnt work here.

Do I have to pass the odds var into the Horse class, in which case, would it have to be declared before the horse1 instance? If so, what if that is not possible - how do I refer to an outside class if it was declared after the calling class was declared?

Thanks lots

[AS2] Self Reference To A Class Instance Within A Class
Hello people!

The question says it, how can I self refer to an instance of a class within the class definition file?

Here is an example


PHP Code:



public function fireBullet(target:MovieClip) {
        Bullet_mc = target.attachMovie("Bullet", "Bullet1", 1);
        }
    } 




Now everytime I want to call the function I have to put this as my target, (fireBullet(this))I cannot just put it in the code as it gives me an error. Could someone please help.

[AS2] Self Reference To A Class Instance Within A Class
Hello people!

The question says it, how can I self refer to an instance of a class within the class definition file?

Here is an example


PHP Code:



public function fireBullet(target:MovieClip) {
        Bullet_mc = target.attachMovie("Bullet", "Bullet1", 1);
        }
    } 




Now everytime I want to call the function I have to put this as my target, (fireBullet(this))I cannot just put it in the code as it gives me an error. Could someone please help.

Reaching For A MovieClip From Another One & Creating An Instance Of A MovieClip
Hello everyone,
I am new to this forum, and I have to say that I find the help and support pretty active here. It's great!
I just started playing around with ActionScript 3, and I am encountering a few obstacles. I did some coding with AS2, but it seems like what I am trying to obtain is done differently now. and I am having difficulties figuring it out by myself. So here are my two questions:
1) I created a movieClip BlueSquare that I put in my library, and I want to create an instance of it when a button is pressed, and then be able to place it on stage at a precise location, and change it's properties. How can I create an instance with a name? Is there an equivalent to the former attachMovie() ? (And while we are at it, how can I then delete that instance?)

2) I am having a major difficulty changing the properties of a movieClip located in another branch of the 'object hierarchy'. Let's say I am in MovieClip11 (where the order could be Stage>MovieClip1>MovieClip11), and I want to change the alpha of MovieClip22 (where the order could be Stage>MovieClip2>MovieClip22). I understood that there are no global variables anymore, but when I try to use the 'parent' and 'root' functions to get to the alpha of that MovieClip22, I am told that I am accessing an undefined property through a reference with static type Class...

thank you for your help, I hope that I was clear in stating my issues.

Daedalus005

Any Way To For A Class Instance To Ask What Its Instance Name Is?
Hey. I have a class which needs to create a movie clip on the stage. Since each instance of the class will only ever have 1 movie clip on the stage at a time, it seems reasonable that I have the instance create a movie clip with its own name, prefixed with "mc_" or something of the sort.

Here's where I don't know quite what to do... How do I get at this information? For instance, when you a dealing with an XMLNode, you can simply use...

the_answer = xmlNodeInstance.nodeName;

...I know the analogy fails, but hopefully you know what I'm looking for.

Thanks!

Class And Instance
I have created about 10 movieclips (enemy1, enemy2....etc..) which all belong to a class called "C_enemy"

If I want to check if there is any hit on the enemies, I need to do this:

if (this.hitTest(this._parent.enemy1)) {
// do sth.
}
if (this.hitTest(this._parent.enemy2)) {
// do sth.
}
...
..
.

But it is too bulky, I don't want to do like this. I would like to know if I can write in one line like this:

if (this.hitTest(class of C_enemy?)) {
// do sth.
}

Get All Instance Of A Class
ok, I'm just wondering if there is a way to get references to ALL the instance for a defined class. Is there an array somewhere holding this? I try to find it but nah, no luck...

Any ideas guys?

A Class That Will Only Have One Instance Ever?
I have scripted an engine for a little game I'm making now. It has quite a bit of code of how to handle things, and some EventHandlers and stuff as well.
now, this engine wont always be used, like when the start-menu and other stuff are being shown.

so i get the feeling it should not always be around. what would be the best aproach for that?

should i make the whole engine into a class, and when it's needed i create an instance of that class?

I have sorta gotten the feeling before that classes are for things that there will be many instances of, but i could be wrong?

is there anything wrong with making a class that i know for sure there will never be more than one instance of? or is there a better aproach?

Thanks in advance =)

Get Class From Instance
How would I get a class from an instance? Basically im trying to compare two instances and see if they are of the same class. Thanks

[AS2 OOP] Best Way To Instance A Class?
Hello everyone. I love Kirupa!

I am wrapping my brain around OOP and I need some advice. I am making two posts on two different subjects.

My question here is: when should I link an AS2 class to a library symbol which I then instance, and when should I use “new” in code to create a new instance of a class? (Feel free to correct my terminology.)

Let’s say I have a menu for general system options. I want to define it in a class called MenuSystem. One of the methods I want to attach to it is “summon”, which makes the menu visible, plays a sound, and changes its contents based on context.

I make a symbol in the Library which lays out all the menu’s elements and give this symbol the linkage identifier “ID_menuSystem”.

It seems I have two ways I can create, initialize, and refer to this thing and darned if I know which is better practice.

***METHOD A:
Make the class MenuSystem extend MovieClip.

The class constructor does not do anything.

In the class, references to the menu clip’s methods are done thusly:
this._visible=true;

In the library, fill in the symbol’s AS 2.0 class as “MenuSystem”.

In my main code, in a startup initialization function, I create the menu on the stage with:
<MC to attach the menu to>.attachMovie(“ID_menuSystem”, “theMenuSystem”, depth)

And then call the method anytime by referring to the instance:
<path>.theMenuSystem.summon();

***METHOD B:
Don’t make the class MenuSystem extend MovieClip.

The class constructor takes an argument “attachTo” for the MC to which the constructed menu’s MC should be attached.

The class constructor has in it:
this.myMC = attachTo.attachMovie(“ID_menuSystem”, “theMenuSystem”, depth);

In the class, references to the clip’s methods are done thusly:
this.myMC._visible=true;

In my main code, in a startup initialization function, I create the menu with:
this.theMenuSystem = new MenuSystem(<MC to attach the menu to>);

And then call the method anytime by referring to the instance:
this.theMenuSystem.summon();

***QUESTION:
Which method should I use, A or B? My main priorities are, in order:
1) Make code that can scale up to be part of a rather complex application.
2) Make code which will be easily reusable in other projects.
3) Make code which is comprehensible to other (real) coders (me being a fake one).

???

Thanks very much for any advice you can give to someone who wants to do good OOP but is lacking much formal training.

Get Instance Name In A Class
Hello!
I have searched around a while, but couldn't find what i'm looking for.

I have created a class: Persons
when I make an instance of this class I want to get the name of this instance and save it as a static var (Array). I want to do this so that i later can call a static function to all instances.

Like this:
var noen: Persons=new Persons("John");
var neon: Persons=new Persons("Mike");
var neonnoe: Persons=new Persons("Karl");
Persons.jumpAll();

And then everybody jumps. (No mater what I called the instances.)

Does anybody know how to do this?
Thanks for your attention.

Mr Amod

Call Function Of Document Class From MovieClip Class
How can I run a function of the main document class from a class of a MovieClip? I usually just used MovieClip(parent).function(), but now my MovieClip has another parent. Or what do I have to pass to the MovieClip class when creating the MovieClip to acess the main document class?

Tween Class In Custom Extend MovieClip Class
I want to use the tween prototype in a custom class that extends MovieClip. I am already including "lmc_tween.as" in my root and I have already replaced the "MovieClip.as" file in my flash directory with the one from the shared/Zigo directory. However, I still get compiler errors if I try to include "lmc_tween.as" in the class file, or without the include in the class it will compile but the tween prototype will not work in the custom class. Does anyone know how to fix this?

Finding A Movieclip Instance Name From Within The Movieclip
I know it is possible to get the id of a movieclip from within side of a movieclip, so that you can use actionscript to find the instance name of the movieclip you are in.

does anyone know the code that will be able to call this?

Cheers

Adam

Accosiating A Class To An MC Instance
hi, would love to know how you accosiate a Class instance with an MC instance in AS2.

this is not working:

Code:
myMCInstanceName = new myClass(arg0,arg1);

Accessing Var's Outside Of A Class Instance
Hi,

I've defined a variable in my main timeline, and I want it to be accessed from inside a function inside a class, but Flash keeps throwing errors at me, how do I do this?

boombanguk

AS2 Class Instance Delete
How do you delete an Object instance created from a Class?

Below is the class from TestDestroy.as


Code:
class TestDestroy extends Key
{
public var myListen:Object
public var aNumber:Number
public var aClip:MovieClip

function TestDestroy(clip:MovieClip)
{
this.aClip=clip
this.aNumber=10
this.myListen=new Object()

Key.addListener(this.myListen)

this.myListen.onKeyDown=this.killME
}

public function killME():Void
{
trace("kill")
delete this
}


}



Now in the flas movie i have


Code:
var destroyTest:TestDestroy=new TestDestroy(_root.Ball)

trace("destroyTest:"+destroyTest)


The trace returns undefined but i can access the Object properties etc.. hence the aNumber and aClip additions.

i cant delete the Object instance from inside the class or from the main timeline.

Obviously it cant find the object as it is undefined, but list the objects when published and its there!.

Very odd

I am transfering to AS2 from AS1 and may have missed something but it is quite confusing that and object instance can exist but cant be destroyed, but can be referenced!

Any pointers gratefuilly recieved

Cheers
JOn

How To Get Path Of Class Instance?
I'm creating a class which will call fscommand to request Javascript to send in some values. I want to pass the path to the class instance to fscommand so that in Javascript I use SetVariable to assign the instance values. But targetpath() doesn't work on classes or objects, only on movieclips. Is there a way that an instance of the class can determine its absolute path?

New Instance's Are Not Created From Class
Hello,
I have created a class called surverySlide in which I have linked to a bunch of slides. each slide registers how many questions it has to the class (itself). The problem is I need each movieclip to be its own instance of SurveySlide ( I have a surveyManager class built to deal with each. I am using attachmovie to show them in sequence on the stage (loading one after the other). I assumed by linking each movie clip to the class a new instance would be created each time but only one instance is created. I.e. the questions are put into an array that should be only for that instance but everytime a new instance is loaded it is added on to the array.

I don't know if I am explaining this clear enough so.....

in each instance of the class (which is a movie clip) I will register the question to that slide...

i.e.

slide instance 1

this.registerQuestion(1);
this.registerQuestion(2);

//if I output the array here I get 1,2

slide instance 2

this.registerQuestion(3);

//if I output the array here I get 1,2,3
//I want it to only output 3

Does anyone know off hand why this is happening?

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