ActionScript 3.0 :: Let 2 Instances Of 1 Class Act The Same

Feb 17, 2009

Is it possible to create 2 instances of 1 class (for example: "Header"). Add these 2 instances to the stage on different positions. This Header class contains some buttons and what I want, is: when I rollOver one of these buttons, both buttons in the 2 Header instances are "rollingOver".

View 1 Replies


Similar Posts:


ActionScript 2.0 :: Make Class Instances Into Listeners And Broadcasters From Inside Each Class?

Jul 8, 2007

I want to know how to make class instances into listeners and broadcasters, from inside each class. Here is what I am trying specifically... part of the Proj class... (projectiles, as a matter of fact)

Code:
private function listen():Void {
u.register(this);
onUpdate = function(){
step(); // a function I have which makes the projectile move (not shown)
}
}

where "u" is another class, the Updater class with this code...

Code:
class Updater {
// const. --- make this a broadcaster
public function Updater(){

[code]....

PS: What is the syntax for using AS2 code tags instead of just "[CODE|"?

View 2 Replies

IDE :: Acesssing Derived Class Children (stage Instances) From Base Class?

Jul 16, 2009

I'm slightly new to Flash CS3 + AS3 combo, so its more of a lack of practice question. My question stems from the problem described here http:[url].... . Note, its not the same problem, its a new one.The Problem ,So I have multiple library assets (which are on teh stage) and I want to assign similar functionality to all of them.

Attempt 1: So I create the n assets, create a custom class in AS3, link them to Flash CS3 and obviously enough it gives me the error that multiple assets can't be linked to the same class.Obvious enough to understand (well not completely, because from a programmers background it doesn't make sense).

Attempt 2: Same as attempt 1, but instead of linking all the assets to the same class I make the base class the same class, and let the derived class be dynamically created by Flash on compile time.So the linking works, but the problem is, in my base class I have a method which does something (say an tween) on a child of the library asset. So if the assets on the stage/library are called asset1, asset2, asset3 (same name for asset name, class name, id name), each of them has a sub-movieclip called ... say 'foo'. now if I manually wrote a class for each asset, I could do 'this.foo' to play with the sub-movieclip. However since this functionality is in the parent class, I'm unable to do it.

P.S. If you're form a programming/OOP background, its basically a abstract class problem. My Base class knows how to doSomething(), but it needs aSomething, which is defined in the Derived classes. However I found out that AS3 classes don't support virtual(C++ )/abstract (Java) in the true sense of the word (unless I missed some obvious documentation).

View 3 Replies

ActionScript 2.0 :: Checking To See If One Instance Of Class Hits Other Instances Of The Same Class?

Dec 23, 2006

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?

View 7 Replies

Flash :: Interact With All Instances Of A Class From A Separate Class?

Jul 25, 2011

I've been hitting dead ends while programming lately all over, and I finally came to the realization all the code I have that is broken is because I don't know how to interact with instances of one class from within another. Here's the gist of what I am trying to do:

if(this.hitTestObject(targetClip)){
trace("hit!");
}

The problem is, if I address a single instance that is on the canvas, I get "access to undefined property targetClip", even though the document class can interact with it fine. If I target the class file of targetClip, I get "Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject". It isn't just a problem with hitTest either, I'm having this problem with other actions, so there is some basic syntax I'm failing to comprehend.

View 2 Replies

Oop - Using The Same Function For Different Class Instances?

Oct 4, 2010

I have a piece of code, that moves an array depending on it's type. If the array is of TypeA objects, it will change TypeA. If it is TypeB it will change TypeB. The issue with the current code is the repeative blocks.

[Code]...

Which stops working whenever I need to access any property (user) selectedInstance.testSomething();

View 1 Replies

Actionscript 3 :: Get Instances By Class Name?

Sep 17, 2011

I need to get all the instances in my stage according to an especific class name. I'm doing this:

var class_ref:Class = getDefinitionByName('fran.MyOwnClass') as Class;
var element;
for (var i:uint = 0; i < this.parent.numChildren; i++)
{

[Code].....

But I want a better way (more efficiently, without checking all the MCs).

View 2 Replies

ActionScript 3.0 :: Way To Create Class Instances?

Oct 8, 2009

I recently learned how to use gravity so I made a bouncing balls program but I have an issue with the interaction between the frame timeline code and the class.The problem is that when I create instances with a timer, I declare the variable inside the timer function. And I want to add a blackhole sort of thing when I click down on the stage but I cannot access the object from the blackhole function since it's declared inside the timer.

View 4 Replies

ActionScript 3.0 :: Controlling Class Instances?

Aug 30, 2009

I have a class the extends a movie clip with some dynamic content in it.I need 15 instances of this class so i created a for loop for that.Im using the same variable name but im just initializing it again and again.

var thumb:MovieClip = new ThumbClass();
addChild(thumb)
my probem is that i need to find a way to control them after i created them.

[code]....

View 3 Replies

Actionscript 3.0 :: Arrays - Get All Instances Of A Class?

Apr 15, 2012

I got a ton of movieclips in a class. Is there a more efficient way to apply a function to every instance in the class other than this?

var textArray:Array = [
interludes.interludeIntro.interludeBegin1,
interludes.interludeIntro.interludeBegin2,

[Code]....

I have NO idea why the above doesn't work. I want to turn every single instance in the class interludeIntro invisible, but I want to turn specific instances visible later.

how to insert code on this website, pressing "code" doesn't do anything, so pardon the bad formatting)

View 2 Replies

Flex - Compare Two Instances Of A Class?

Oct 8, 2009

Let's say I have created a class named Store. This class has several elements such as Name, PhoneNumber, Owner. I've created 2 instances of this class and want to know which values are different. So lets say that Store1 and Store2 are instances of this class.

Store1.Name = "John's Corner";
Store1.PhoneNumber = 111222333;
Store1.Owner = "John";
Store2.Name = "John's Corner";
Store2.PhoneNumber = 444555666;
Store2.Owner = "John";

[Code]...

Is there a way to automatically loop through all elements of a class instance and compare them to the same element in another class instance and return something when they differ?

This might be obvious but I can't figure it out.

View 5 Replies

Actionscript 3 :: Using Instances Already On Stage From Another Class?

Feb 23, 2011

I'm new to this OOP stuff, and I'm having a hard time understanding all of this.I'm trying to recreate in AS3.0 with classes a simple whack-a-mole game I created in AS2.0 using timeline coding.I've read through a lot of forums, but I still don't understand what exactly I'm doing wrong.Heres my setup:I have a movie clip named mrBunny (my girlfriend told me to change it to bunnies as moles were too ugly.). Now there are 6 instances of mrBunny on the stage, each named mrBunny0-5.The mrBunny symbol is linked to the com.mrBunny class.The class has a method called randomPlay(); which I use to randomize the animation times of mrBunny.I also have a button on the stage with the class stageBtn.

package com{
import flash.display.SimpleButton;
import flash.display.MovieClip;

[code].....

View 2 Replies

ActionScript 2.0 :: Renaming Class-instances?

Dec 9, 2004

Is it possible to rename a class-instance that has already been created with a specific name?For instance:

// Step 1) Create and name class-instance
var myClassInstance_1:myClass= new myClass();
// Step 2) Change name of myClassInstance_1

[code].....

View 3 Replies

ActionScript 2.0 :: [OOP] Tracing Instances Of Class

Jul 4, 2003

[Code]...

this's been bugging me, anyone know what's wrong?

View 14 Replies

ActionScript 2.0 :: Multiple Instances Of Class?

Jun 11, 2009

I am making an AS 2.0 Class for polygons called "Shapes2". Shape2 is basically an array of Vectors (another Class I made) and is built using the function addPoint(x1,y1) to build the shape from a series of points. The points are then converted to vector-edges, etc etc.Here's the long and complicated construction:

Code:
var pent:Shape2 = new Shape2();
var rect:Shape2 = new Shape2();

if I comment out either instance, the other is functional when I test it. Trying to do two instances makes rect and pent point to the same array of vectors, but they keep other variables and properties separate, which means rect isn't just pointing directly to pent or visa versa.

View 1 Replies

ActionScript 3.0 :: Instances Of A Class Sharing 'this' Value?

Feb 3, 2010

I have four instances of the same class called Tile, that is bound to a movieclip with four frames. They're imbedded in a movieclip that I'm using to hold all of the visuals.In the main class of my .fla I declare a variable called menu1 that is bound to another movieclip with 2 buttons on it.

I'm trying to make three things happen here: on clicking the Tiles the menu will pop up over the tile that was clicked; that on clicking another tile when the menu is already up it will close that one before adding a new one; and lastly, that on clicking the second button in the menu, it will change the frame of the tile clicked and close the menu.The tile.as has an addeventlistener in it's construction method to add the function onTileClick to each Tile.

public class Tile extends MovieClip{
public function Tile():void{
addEventListener(MouseEvent.CLICK, onTileClick);[code]....

This works fine for one tile. I can click on it, the menu pops up, I can close and reopen the menu as many times as I want, and I can use the other button with no problems.Also, clicking around on different tiles moves the menu around without repeatedly adding it, so that seems to be working fine as well.The problem is this: If I click on a tile, close the menu, then click on another tile and close it, I get an error 1009.It still closes, that error just comes up. And it will come up for any more tiles I open and close it on.Then, after clicking on however many tiles, if I do click the advance button, it affects all of the tiles, and I get an ArgumentError: Error #2025 for each tile clicked on.I tried adding a variable that held the event.target value in the onAdvance function, and using that for the gotoAndStop, but the same thing happened. When I tried tracing the name of the variable, I noticed that it was tracing the names of each tile clicked with each subsequent trace.

Am I building this all wrong?I thought that making a class for my tile object, and adding eventlisteners to the class, and adding the functionality of the tiles inside of the class would be good practice for Object Oriented Programming, but it seems to be producing nothing but errors. When I defined these tiles inside the main timeline, with separate event listeners, I didn't have this problem

View 3 Replies

ActionScript 3.0 :: Collision With Other Instances Of Same Class

Jan 29, 2011

I'm trying to make it so that the instances of the class "Enemy" stop completely when they get too close to each other. They are circles so determining a collision is easy. But when I used this code:

Code:
if (Math.sqrt(Math.pow(x-_root.newEnemy.x, 2)+Math.pow(y-_root.newEnemy.y, 2))<=width+3) {
canMove=false;
}

[Code]....

This code works just fine when I test it against the instance of a different class, but it's not working for some reason.

View 13 Replies

ActionScript 3.0 :: Can't Set Properties From Instances Of Class?

Jun 9, 2011

I have a class - call it MyClass - and an instance of that class with instance name myObject.In MyClass I declare:

public var myVariable:Number;
In the main timeline I try to set it using myObject.myVariable = 3;

In the main timeline, if I do a trace (myObject.myVariable) it will return 3. Within the class, if I do a trace of (this.myVariable) it returns null.However, if I add a line of code in my class and add this.myVariable = 3, it traces 3.Why can't I get myObject to correctly change its own parameters?

View 2 Replies

ActionScript 3.0 :: Set Certain Properties To All Instances Of Class (mc From Library)

Jul 17, 2009

I've created a movie clip and placed it in the library. I've given it a class name via the properties panel in the library. Every time I drag it to stage I want to make sure its alpha is set to 0. If I drag 300 of those clips to stage, is there a way to reference the class name I gave it in order to automatically set the alpha value as soon as they're dragged into the stage?

View 2 Replies

ActionScript 3.0 :: Class Instances And Null Values?

Sep 22, 2008

I'm currently stumped by this. I've created a class to load xml data from a txt file, then assign that xml to a variable named siteStructureXml. When I trace the value of siteStructureXml from within the class instance it shows the expected xml data. When I try to assign the value to a variable returnedXml defined on the timeline of my movie, it's value traces as null. I've a feeling it's something blindingly obvious..

[Code]...

View 3 Replies

ActionScript 3.0 :: Base Class Does Not See Stage Instances

Apr 1, 2010

I'm writing a series of Search windows for an application. I create the FLA files on the stage, each has 3 simple buttons: next_btn, prev_btn, and close_btn. Those all have event listeners which call findNext(), findPrev() and closeWin() respectively. Each search window looks for different things, some with a text box and some with a combo, etc.
 
So I have a base class com.search that extends Sprite and adds the eventListeners at startup (actually, on addedToStage). Like this:
 
function isAddedToStage(evt:Event){
next_btn.addEventListener("click",findNext);   prev_btn.addEventListener("click",findPrev);   close_btn.addEventListener("click",closeWin);}

[Code]....
 
If I add the event listeners in the derived class rather than the base, it works fine. But that seems to defeat the purpose of inheritance, plus it infers that I won't be able to derive new classes/swfs from those derived classes.
 
how does one reference objects created on the stage from a base class of that document's class?

View 4 Replies

ActionScript 3.0 :: How To Avoid Multiple Instances Of A Class

Apr 14, 2011

new a class [code]Now ,I want call function newCourse many times and don`t new class again.

View 2 Replies

Actionscript 3 :: Manipulate Different Instances Of A Class From The Timeline?

Feb 17, 2011

i am trying to create a menu using as3 and i cant seem to find a way to finish it.this is what i got so far

so i wrote a class that is attached to a movieclip and i put several instances of it on the stage.

package {
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.display.*;

[Code]...

I wanted the animation to not roll back once i click on a certain button and i wanted the animation to go back once i click on a different button. My question is, how do i proceed from here, i searched online for clues and from what i understood i could set variables within the class and change them on the timeline and use event listeners to catch the changes. I tried doing that but i always end up with some redundant way that gets me nowhere...

View 1 Replies

Actionscript 3 :: Get An Array Of All Instances Of A Class On A Stage?

May 22, 2011

Assume I have the myCircle class all defined and all that. If my code is as follows:

[Code]...

How would I write a function to return an array of [circle1, circle 2, circle3, circle4] automatically?

View 2 Replies

ActionScript 3.0 :: 3 Instances Of 1 Class Share Variable?

Feb 22, 2009

I have a button class and I made 3 instances of that button class as.. btn1, btn2 and btn3 Is it possible for the btns to share a global variable or something? For instance what I am trying to do. if btn1 is pressed it triggers a global variable "isClick = true" and if I click on a different button (btn2 or btn3) it checks to see if isClick is true then it calls a function A if not then calls different function B.

View 1 Replies

ActionScript 3.0 :: Accessing Nested Instances From Another Class?

Feb 2, 2010

I made a movieclip (map) with nested instances (cities) in IDE and I want to access them from non-document class.

But the class can't access them until it's added at the stage too.

If I add the class at stage, class can see and access only map, but not cities inside of it.

Both class and map are children of document class...

View 0 Replies

ActionScript 3.0 :: Loop Over Instances Of A Class-object?

Feb 5, 2010

i am creating a certain amount of instances of a class-object (called Jaar).When i click on one of them, I would like to change a value (isSelected) in all the instances of this class.How can i do this?So far i have this (simplified version) :

ActionScript Code:
package{
import flash.display.*;

[code].....

View 6 Replies

ActionScript 3.0 :: Dynamically Creating Class Instances

Apr 26, 2010

I have a class subclass1.I want to be able to do something like this,[code]

View 4 Replies

ActionScript 3.0 :: Multiple Instances Of A Class Having Conflictions?

May 22, 2010

I have a "Window" class, which will create a window with the parameters you specify. One of the functions inside of that class is to place an element inside the window - something such as a text field, button, etc.

Now my issue. I've created two windows with different names, slightly different parameters, etc. I am adding a text field to each one. On the screen, both text fields show up (have borders enabled). I can refer to both windows using getChildByName(), but for one reason or another I can only find one text field using the getChildByName method. The other one will give me an error.... "Cannot access a property or method of a null object reference."This is the code that I use to add a Text Field, keep in mind this is inside the window class:

ActionScript Code:
public function element(builder:Object) {
switch (builder.type) {
case "static_text" :

[code]....

This code is repeated twice, for different windows. The only thing that's different about them is their names, which are slightly different. It seems that whichever text field I add first gets to stay, while an subsequent ones appear on the screen, but I cannot refer to them. I've tried switching around the window definitions and that does seem to be the case.

View 7 Replies

ActionScript 3.0 :: Creating Instances Of A Class Using A Loop

Oct 30, 2010

basically i want to create ten balls on the stage. I have a balls.as file which uses the drawing api to create a circle within it. also within the balls.as file there is a public variable.[code]how would i go about finding out: if you click one of the balls it traces that balls life.

View 9 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved