Basic actionscript help, tracing properties of my class object
Hi all,I'm just starting to learn about classes in actionscript, I am following along with Moocks book Actionscript for Flash MX and are trying to execute a trace on the properties of my ballclass but all I get is undefined. He is what I have in my actions panel.
function Ball () {
this.radius = 10;
this.color = 0xFF0000;
this.xPosition = 59;
this.yPosition = 15;
var boucyBall = new Ball();
trace (bouncyBall.radius);
trace (bouncyBall.color);
trace (bouncyBall.xPosition);
trace (bouncyBall.yPosition);
Any help would be great
Since you are learning about classes, you might want to use one to help you:
class Util{
public function Util(){
// empty constructor because you don't need one for this kind of class
public static function traceProps(obj:Object,label:String):Void{
if(label != undefined){
trace(Properties for "+label+":");
for(var a in obj){
trace(" "+a+": "+obj[a]);
trace(newline);
Then place that class file somewhere in your class path so it will always be available to you. And then you can always add these lines.
import com.complexity.Utils;
If the file is in your class path you don't really need the above line, but it will help you remember that you are using it. Also I'm just making up what your class path might be based upon your screen name. You would need to use whatever actual path you had. And then...
Utils.traceProps(bouncyBall,"trouble maker here");
Of course don't use it with an 10,000 element array, unless you really like to suffer.....
or just
Utils.traceProps(bouncyBall);
Similar Messages
-
Re: Beginner needs help using a array of class objects, and quick
Dear Cynthiaw,
I just read your Beginner needs help using a array of class objects, and quick of Dec 7, 2006 9:25 PM . I really like your nice example.
I also want to put a question on the forum and display the source code of my classe in a pretty way as you did : with colors, indentation, ... But how ? In html, I assume. How did you generate the html code of your three classes ? By help of your IDE ? NetBeans ? References ?
I already posted my question with six source code classes ... in text mode --> Awful : See "Polymorphism did you say ?"
Is there a way to discard and replace a post (with html source code) in the Sun forum ?
Thanks for your help.
Chavadachavada wrote:
Dear Cynthiaw,
I just read your Beginner needs help using a array of class objects, and quick of Dec 7, 2006 9:25 PM . I really like your nice example.You think she's still around almost a year later?
I also want to put a question on the forum and display the source code of my classe in a pretty way as you did : with colors, indentation, ... But how ?Just use [code] and [/code] around it, or use the CODE button
[code]
public class Foo() {
* This is the bar method
public void bar() {
// do stuff
}[/code] -
Help with dynamic creation of class object names
Hi all
Wonder if you can help. I have a class player.java. I want to be able to create objects from this class depending on a int counter variable.
So, for example,
int counter = 1;
Player p+counter = new Player ("Sam","Smith");the counter increments by 1 each time the method this sits within is called. The syntax for Player name creation is incorrect. What I am looking to create is Player p1, Player p2, Player p3.... depending on value of i.
Basically I think this is just a question of syntax, but I can't quite get there.
Please help if you can.
Thanks.
Samhere is the method:
//add member
public void addMember() {
String output,firstName,secondName,address1,address2,phoneNumberAsString;
long phoneNumber;
boolean isMember=true;
this.memberCounter++;
Player temp;
//create HashMap
HashMap memberList = new HashMap();
output="Squash Court Booking System \n";
output=output+"Enter Details \n\n";
firstName=askUser("Enter First Name: ");
secondName=askUser("Enter Second Name: ");
address1=askUser("Enter Street Name and Number: ");
address2=askUser("Enter Town: ");
phoneNumberAsString=askUser("Enter Phone Number: ");
phoneNumber=Long.parseLong(phoneNumberAsString);
Player p = new Player(firstName,secondName,address1,address2,phoneNumber,isMember);
//place member into HashMap
memberList.put(new Integer(memberCounter),p);
//JOptionPane.showMessageDialog(null,"Membercounter="+memberCounter,"Test",JOptionPane.INFORMATION_MESSAGE);
//create iterator
Iterator members = memberList.values().iterator();
//create output
output="";
while(members.hasNext()) {
temp = (Player)members.next();
output=output + temp.getFirstName() + " ";
output=output + temp.getSecondName() + "\n";
output=output + temp.getAddress1() + "\n";
output=output + temp.getAddress2() + "\n";
output= output + temp.getPhoneNumber() + "\n";
output= output + temp.getIsMember();
//display message
JOptionPane.showMessageDialog(null,output,"Member Listings",JOptionPane.INFORMATION_MESSAGE);
}//end addMemberOn running this, no matter how many details are input, the HashMap only gives me the first one back....
Any ideas?
Sam -
i confess, i am a newbie. i have been working with a
template, modifying it to my needs. i have ran into an actionscript
code that i cant seem to find the reference to in the books. it is:
_root.G
can someone point me toward the proper reference material to
read up on this?
thanks!Basically the "_root" part of the script references your main
timeline. Meaning your not inside a symbol but you are working
directly on the main timeline. So what you are probably doing here
is referencing a movie clip on the main timeline with the instance
name "G".
For example, if I wanted to tell a movie clip named G sitting
on my main timeline to start playing from frame label startHere I
would write the following code:
_root.G.gotoAndPlay("startHere"); -
Need Help in trying to understand class objects
I need help on understanding following problem.I have two files for that, which are as follows:
first file
public class Matrix extends Object {
private int matrixData[][]; // integer array to store integer data
private int rowMatrix; // number of rows
private int colMatrix; // number of columns
public Matrix( int m, int n )
{ /*Constructor: initializes rowMatrix and colMatrix,
and creates a double subscripted integer array matrix
of rowMatrix rows and colMatrixm columns. */
rowMatrix = m;
colMatrix = n;
matrixData = new int[rowMatrix][colMatrix];
public Matrix( int data[][] )
{ /* Constructor: creates a double subscripted integer array
and initilizes the array using values of data[][] array. */
rowMatrix = data.length;
colMatrix = data[0].length;
matrixData = new int [rowMatrix][colMatrix];
for(int i=0; i<rowMatrix; i++)
for(int j=0; j<colMatrix; j++)
matrixData[i][j] = data[i][j];
public int getElement( int i, int j)
{ /* returns the element at the ith row and jth column of
this matrix. */
return matrixData[i][j];
public boolean setElement( int x, int i, int j)
{ /* sets to x the element at the ith row and jth column
of this matrix; this method should also check the
consistency of i and j (i.e., if i and j are in the range
required for subscripts; only in this situation the operation
can succeed); the method should return true if the operation
succeeds, and should return false otherwise.
for(i=0;i<rowMatrix;i++){
for(j=0;j<colMatrix;j++){
x = matrixData[i][j];
if(i<rowMatrix && j<colMatrix){
return true;
else{
return false;
public Matrix transposeMatrix( )
{ /*returns a reference to an object of the class Matrix,
that contains the transpose of this matrix. */
Verify tata;
Matrix trans;
//Matrix var = matrixData[rowMatrix][colMatrix];
for(int row=0;row<rowMatrix;row++){
for(int col=0;col<colMatrix;col++){
matrixData[rowMatrix][colMatrix] = matrixData[colMatrix][rowMatrix];
trans = new Matrix(matrixData);
return trans;
public Matrix multipleMatrix( Matrix m )
/*returns a reference to an object of the class Matrix,
that contains the product of this matrix and matrix m. */
m = new Matrix(matrixData);
//Matrix var = matrixData[rowMatrix][colMatrix];
for(int row=0;row<rowMatrix;row++){
for(int col=0;col<colMatrix;col++){
//trans[row][col] = getElement(row,col);
return m;
public int diffMatrix( Matrix m )
/*returns the sum of the squared element-wise differences
of this matrix and m ( reference to the formula in the description
of assignment 5) */
return 0;
public String toString( )
/* overloads the toString in Object */
String output = " row = " + rowMatrix + " col="+colMatrix + "\n";
for( int i=0; i<rowMatrix; i++)
for( int j=0; j<colMatrix; j++)
output += " " + getElement(i,j) + " ";
output += "\n";
return output;
Second file
public class Verify extends Object {
public static void main( String args[] )
int[][] dataA = {{1,1,1},{2,0,1},{1,2,0},{4,0,0}}; // data of A
int[][] dataB = {{1,2,2,0},{1,0,3,0},{1,0,3,4}}; // data of B
Matrix matrixA = new Matrix(dataA); // matrix A
System.out.println("Matrix A:"+matrixA);
Matrix matrixB = new Matrix(dataB); // matrix B
System.out.println("Matrix B:"+matrixB);
// Calculate the left-hand matrix
Matrix leftFormula = (matrixA.multipleMatrix(matrixB)).transposeMatrix();
System.out.println("Left Side:"+leftFormula);
// Calculate the right-hand matrix
Matrix rightFormula = (matrixB.transposeMatrix()).multipleMatrix(matrixA.transposeMatrix());
System.out.println("Right Side:"+rightFormula);
// Calculate the difference between left-hand matrix and right-hand matrix
// according to the formula in assignment description
double diff = leftFormula.diffMatrix(rightFormula);
if( diff < 1E-6 ) // 1E-6 is a threshold
System.out.println("Formula is TRUE");
else
System.out.println("Formula is FALSE");
}My basic aim is to verify the formula
(A . B)' =B' . A' or {(A*B)tranpose = Btranspose * A transpose}Now My problem is that I have to run the verify class file and verify class file will call the matrix class and its methods when to do certain calculations (for example to find left formula it calls tranposematrix() and multipleMatrix();)
How will I be able to get the matrix which is to be transposed in transposeMatrix method (in Matrix class)becoz in the method call there is no input for transposematrix() and only one input for multipleMatrix(matrix m).
please peeople help me put in this.
thanking in advancePlease don't crosspost.
http://forum.java.sun.com/thread.jspa?threadID=691969
The other one is the crosspost.Okay, whatever. I'm not really concerned with which one is the original. I just view the set of threads overall as being a crosspost, and arbitrarily pick one to point others toward.
But either way
knightofdurham... pick one thread and post only in
the one.Indeed. And indicate such in the other one. -
Loading and viewing XML when a class object is created..Help Please
Hello,
I have writing a simple class which has a method that gets invoke when the object of the class is created. I am able to view the loaded XML content when I trace it with in my class method, but cannot assign the content to a instance variable using the mutator method. So the process goes like this:
Class object is instantiated
Class construtor then calls the loadXML method which laods the XML
And then assigns the XML to a class instance variable.
So now if I would like to access the loaded XML through class object, I should be able to see the loaded xml content which I am not able to see. I have spent over few hours and cannot get the class object to display the loaded XML content. I would highly appreciate it if someone can help in the right direction, please.
[code]
package com.as3.app
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
public class Cars extends MovieClip {
public var _CarList:Object;
public function Quiz()
super();
loadCars();
// ===========================================================
// CARS GETTER SETTER
// ===========================================================
public function set Cars(val:XML):void
this._CarList = val;
public function get Cars():XML
return this._CarList;
// ===========================================================
// LOAD QUESTIONS FROM XML
// ===========================================================
public function loadcars()
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("xml/cars.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
myXML = new XML(e.target.data);
Cars = myXML; // Assigning the loaded xml data via mutator method to the _CarList;
//=============================================================
INSTANTIATING THE CLASS OBJECT
//=============================================================
package com.as3.app
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
import com.as3.app.*;
public class DocumentClass extends MovieClip {
public var c:Car;
public function DocumentClass()
super();
c = new Cars();
trace(c.Cars);
[/codewhere you have:
super();
c = new Cars();
trace(c.Cars);
c.Cars will not trace as the loaded xml, because it will not have loaded in time. After some time it should presumably have the correct value.
loading operations in actionscript are asynchronous, so your nested function which is acting as the listener ( function processXML(e:Event):void) only ever executes when the raw xml data has loaded and that is (I believe, not 100% sure) always at least one frame subsequent to the current one.
In general I would consider it bad practise to use nested functions like that, but I don't think its contributing to your issues here. I think its just a timing issue given how things work in flash....
Additional observation:
your Cars constructor calls loadCars() and your loadCars method is defined as:
public function loadcars()
I assume its just a typo in the forum that the uppercase is missing in the function name.... -
Basic Actionscript 3.0 OOP Confusion
I'm having a difficult time getting basic Actionscript OOP
principles to work in my code. I have an application I'm building
that extends the Sprite object. I try to instantiate another Sprite
object, and specify the with/height/x/y values to size this new
object, but it never properly sets these values. If I trace the
width/height, etc. they're always equal to 0. I'm not exactly sure
what I'm doing wrong.
The 3 different sizing syntax I've tried are:
graphics.drawRect(0,0,width,height); // DOES NOT WORK
graphics.drawRect(0,0,parent.width,parent.height); // WORKS
graphics.drawRect(0,0,600,400); // WORKS
Code is posted below:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import ChartPanel;
public class Chart extends Sprite
private var chartType:int;
private var chartPanel:ChartPanel;
public function Chart()
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
graphics.beginFill(0xffffff);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
// Fill BG as White
graphics.endFill();
chartPanel = new ChartPanel();
chartPanel.setDimensions(600, 400, 0, 0);
addChild(chartPanel);
chartPanel.draw();
package
import flash.display.Sprite;
public class ChartPanel extends Sprite
public function ChartPanel() {}
public function setDimensions(w:int, h:int, off_l:int,
off_t:int):void
this.width = stage.width;
this.height = stage.height;
this.x = off_l;
this.y = off_t;
public function draw():void
trace("DRAWING: this.width=" + this.width + " this.height="
+ this.height + " this.x=" + this.x + " this.y=" + this.y);
graphics.beginFill(0x0000ff);
// DOES NOT WORK graphics.drawRect(0,0,width,height);
graphics.drawRect(0,0,parent.width,parent.height);
graphics.endFill();well... you still don't grab the hole width and height
concept, as I told you they are MEASURES not fixed variables, so by
setting a width and a height you are not defining a biding
rectangle with content in ti, the Sprite class simple doesn't have
the code for that, the Sprite is simply an elements with things in
it, now actual border or frame.
For what you want you'll still need your invisible rectangle,
but it will have to be a MASK of the sprite class.
As for the code (NOTE I'M JUST WRITING HERE SO IT CAN HAVE
SOME BUGS) it should be something like this:
public class Box extends Sprite {
private var border:Shape;
private var _width:Number = 100;
private var _height:Number = 100;
public function Box() {
border = new Shape();
addChild(border);
mask = border;
drawDispArea();
private function drawDispArea():void {
border.graphics.clear();
border.graphics.beginFill(0xFF0000);
border.drawRect(0, 0, width, height);
override public function set width(v:Number):void {
_width = v;
drawDispArea();
override public function get width():Number {
return _width;
override public function set height(v:Number):void {
_height = v;
drawDispArea();
override public function get height():Number {
return _height;
} -
BI JDBC - How to configure Helper.jdbc.properties?
Hi,
I am little bit confused regarding where to configure
Helpers.jdbc.properties.
In a new project I have placed the Helpers.java and
exported it as a par.And from the .PAR i extracted the
jar file and included it in my JDBC project.
Pl. suggest how to configure the Helper.jdbc.properties.
regards
MrutyunjayFriends,
Would be thankful for any hints.
Thanks & Regards
Mrutyunjay -
Basic Data Types as Class Objects
Consider the following code using the java.lang.reflect.Method
Class c = Class.forName("java.util.Date");
// get all methods in Date
Method[] c_classes = c.getMethods();
// get the UTC method - UTC(int year, int month, int date, int hrs, int min, int sec)
Method m = c_classes[0];
// get the parameters (all int)
Class[] p = m.getParameterTypes();
This gives a Class array of basic data types (in this case int) - in debug the variable is of type "class" with value "0x16d9220:class(int)"
How do you create a Class object of a basic data type from scratch? I've tried Class.forName("int") and get an exception.
Cheers
GarethYou could use the class literals.
Class[] primitiveTypes = {
boolean.class,
byte.class,
char.class,
double.class,
float.class,
int.class,
long.class,
short.class,
Cheers, that's exactly what I needed.
Gareth -
Properties of a class-System Table
Hi All,
I would like to know the name of the system table where the properties of a class (like the superclass of the class) are stored.
I have to create an interface or a class such that it is inheriting from an other class(super class) using code.I am able to create the class using function module SEO_INTERFACE_CREATE but don't no how to make it inherit from some class.
Ur replies are valuable.
Thanks in advance.
Hemahi try this FM
<b>CC_LS_GET_CLASS_HIER_STRUCTURE</b>
plz let me know if it is helpful -
Help on java.sql.Types class
Hai Friends ,
I want some help on java.sql.Types class .
What is the use of the above class ?
Some details about this class.Good Morning Yekesa
First of all i would like to thank U for looking into my problem.
I am using java.sql.Types.OTHER for
{"?=CALL(storedprocedurename.functionname(?))"}
registerOutParameter(1,javal.sql.Types.OTHER)
setString(2,"user")
here the
second parameter passes an argument to function name ( viz. username say "user")
and the function will return the ref cursor as follows:
// declaration in pl/sql procedure
begin
rc ref cursor
open rc for select * from ss_user where login_name="user";
return rc;
end
now the stored procedure has a return value (i.e. stored function) which it needs to register as
registerOutParameter(1,javal.sql.Types.OTHER)
and it finally results in the following errors :
Loading driver
Before conn stmt
After conn stmt
Calling Stored procedure
Stored procedure called
java.sql.SQLException: Invalid column type
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:243)
at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:2487)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:64)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:54)
at sptest.<init>(sptest.java:28)
at sptest.main(sptest.java:49)
T couldn't understand why it is saying Invalid Column Type because its working fine with both
java.sql.Types.INTEGER
and
java.sql.Types.VARCHAR
Pl help me at the earliest as i have wasted a lot of time on it.
pl mail me in detail at [email protected]
bye then
bansi
null -
Please help how to set/get a class object in hashtable or hashmap?
Hi, everybody.
I'd like to generate a class-object list in hashtable.
However, compilation is error. Here is my code:
Hashtable ht = new Hashtable();
Class tmp_obj;
tmp_obj = Class.forName("my_class_name_1");
ht.put("my_class_name_1", tmp_obj);
tmp_obj = Class.forName("my_class_name_2");
ht.put("my_class_name_2", tmp_obj);
Class selected_object = ht.get("my_class_name");
^here compilation error: incompitable types
Could anybody tell me where is wrong in my code and how to
correct it?
Thank you in advance.
JeffLook at the javadoc for Hashtable. The get method returns an Object. You will need to cast it to a Class object.
Class selected_object = (Class)ht.get( "my_class_name" );If you are using JDK5.0, then you should look up generics. -
Access properties of the class passed to a thread
Hi You all,
I have the following code:
package com.services;
import java.util.*;
public class Timer implements Runnable
// CLASS OBJECTS
private int interval;
private volatile int clockFlag = 0;
// CONSTRUCTOR
public Timer()
public void stop()
this.interval = 0;
public void setInterval(int pInterval)
this.interval = pInterval + 100000000;
public void run()
while(this.interval != 0)
if(this.clockFlag == this.interval)
System.out.println("clockFlag");
this.clockFlag = 0;
this.clockFlag ++;
Timer objTimer = new Timer();
objTimer.setInterval(5);
Thread objThread = new Thread(objTimer);
objThread.start();So if I want to use the run method of the Timer class what should I do?
Is there any method in the thread that alows me to call any method of the class passed to it?
Thanks,
MeTitusThat's usually a bad design choice.why?You should extend when you actually want to add some new functionality to a class, and the OP doesn't want to create a new type of thread. He just want to execute something in a new thread.
Kaj -
How to get a LabVIEW class object to expose an invoke-node method?
Hi,
I like the property/invoke-node "paradigm" used for interacting with "objects". Can LabVIEW-class objects expose their properties and methods this way? Can one or more LabVIEW-class objects be compiled into a library or "assembly" (or other distrubution format) that allows the property/invoke-node usage?
I've looked at (but not completely understood) "Creating LabVIEW Classes". Have also searched for related posts.
The pic below shows an invoke node wired to a class with a Public VI "VAT.Status.Hello.vi". I'd like to see VAT.Status.Hello show-up as a Method. (I just tried "Select Method", and selected "VAT.Status.Hello.vi" but dialog's "OK" button stays greyed-out.)
Cheers.
Message Edited by tbd on 03-29-2007 03:15 PM
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Attachments:
VATStat.JPG 54 KBHi Aristos,
Thanks for the reply! It was a bit dissappointing, though.
It appears the LabVIEW-class object will be moving away from (what seems to me) a convenient object-interface presented by the invoke-node/method paradigm - which allows us to interface with a large set of "objects" (.NET, ActiveX, LabVIEW GUI, VISA Resource, ?) in a similar manner and independent of the object's origin. Being able to read the methods and parameters that appear in these nodes is also helpful for understanding diagram logic!
I do like the option of dropping a friendly "VI looking" icon on the diagram, but perhaps an optional - even default - VI-icon representation for a class-object invoke-node is feasible - so the LabVIEW class-object could be the more generic object first, but with a traditional-G representation(?)
Given the answer "We would like, someday, to support the property node"
and "in the next version of LV, wiring the LV class to the property/invoke nodes will break the wire so we'll avoid confusion in the future",
... I guess you'll break the wire in the next version, but (perhaps) allow it again - if support of the property node is ever implemented?
Regards.
P.S. For the record, huge THANKS to whoever it was that straightened-out enumerated-types (somewhere) between LV4.1 and LV6.1. Every time I add or remove an enumeration in a typedef, I silently give thanks to the bright and thoughtful soul(s) who made this valuable tool work so well!
Hello. This is your friendly neighborhood R&D guy for LabVIEW classes.
Regarding your request about property and invoke nodes as relates to LV classes....
Short story: We would like, someday, to support the property node. We have no intention of ever supporting the invoke node.
Long story: As we were creating LV classes, we had to evaluate the right programming interface for these things. We wanted LV classes to behave as new data types in LV. A developer should be able to create a LV class, then give it to someone who doesn't even know OO programming, and that second programmer could use the new data type without learning a lot of new concepts. From this principle, we held fast to the idea that the programming interface should be subVI calls whereever possible. The invoke node is really nothing more than a VI minus the icon. If you want, you can popup on any subvi node and uncheck the option "View as Icon". This will make the node display in a way that has the terminals listed as text, like the invoke node. So, at the end of the day, the invoke node is simply a subroutine call in LV that is language dependent, as opposed to the language independent iconography of LV generally.
The property node is a slightly different story -- the functionality of a property node is actually different than an invoke node as its terminals are various subsets of the properties available, not a fixed list of parameters like the invoke node. The property node provides a nice interface for setting multiple properties in a block and only having to check a single error return. Very friendly. Our intent is to allow you to create a VI that has 5 terminals: object in, object out, error in, error out, and either a single input or a single output of your chosen type. VIs with this conpane could be marked as "properties" of the class and would show up when you wire the class wire to the property node. We would call the subVIs behind the scenes as needed to get/set the properties.
This is on the longer term roadmap because it is "syntactic sugar" -- it sweetens the programming style, but it is not necessary to program effectively. You can get the same effect by writing those same VIs and stringing them along on a block diagram "railroad track" style. We'll probably get around to it in three or four versions of LV -- there are some major user requests that impact functionality that have to get done first.
PS -- in the next version of LV, wiring the LV class to the property/invoke nodes will break the wire so we'll avoid confusion in the future of people thinking there's a way to use these nodes.
Message Edited by Aristos Queue on 04-02-2007 09:56 AM
Message Edited by tbd on 04-03-2007 12:39 PM
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare) -
As 2.0 class objects- how to swap depths of a movie clip
How do you bring an object to the top? if it's just a movie
clip, I could do a swapdepths, but if it's a movieclip that's part
of an AS 2.0 object, how do you swap depths of the whole object?
I create 2 objects (same class) which each have a movieclip
within them. The movie clip is created on a unique level with
getNextHighestDepth().
I have a button which tries to swapDepths of the 2 objects,
but I can't get it to work. Can anyone help?
here's the detail:
1. create a symbol in the library called "someShape_mc" and
put some shape in it - a circle, a square, whatever - this symbol
is exported for action script, and has an AS 2.0 Class of
"ClassObject" ( I also put a dynamic text field in the shape to
display the current depth - it's called "depth_txt")
2. create a button called "swap_btn" on the stage.
Frame 1 has the following actionscript:
var BottomObject:ClassObject = new ClassObject(this,100,150);
var topObject:ClassObject = new ClassObject(this,110,160);
// for the button add this:
Swap_btn.onRelease=function() {
// try it with the full path:
_root.BottomObject.__LocalMovieClip.swapDepths(_root.topObject.__LocalMovieClip);
// try it with with just the objects:
BottomObject.__LocalMovieClip.swapDepths(topObject.__LocalMovieClip);
// try it with the object as a movieclip
BottomObject.swapDepths(topObject);
trace("Did it Swap?");
// try it with a method in the class....
BottomObject.swapIt(topObject.__LocalMovieClip);
BottomObject.swapIt(topObject);
trace("nope... no swapping going on...");
================================
here's the AS file: "ClassObject.as"
class ClassObject extends MovieClip{
var __LocalMovieClip;
var __Depth;
function ClassObject(passedIn_mc:MovieClip,x:Number,y:Number)
__Depth = passedIn_mc.getNextHighestDepth();
__LocalMovieClip =
passedIn_mc.attachMovie("someShape_mc","__LocalMovieClip",__Depth);
trace("made a shape at " + __Depth);
__LocalMovieClip._x = x;
__LocalMovieClip._y = y;
__LocalMovieClip.depth_txt.text = __Depth;
public function swapIt(targetMc) {
__LocalMovieClip.swapDepths(targetMc);
__LocalMovieClip.depth_txt.text =
__LocalMovieClip.getDepth(); // no difference.
trace("Tried to swap from within the class...");
========================
so- the goal is to bring the "bottom" Class object on top of
the "top" object. The button tries various methods of swapping the
depths of the movie clips - but there is not one that works. What
am I missing?
tia
ferdThank you for your response - and here I have included the
code I reworked to show how it works, and doesn't work. you're
right about not needing the extra containers, but this example is
part of a bigger thing...
I'm confused - it works ONLY if I attach the movie outside
the class, even though the "attachment" occurs, I'm thinking, at
the same scope level, that is, _root.holder_mc, in both examples.
it seems that the advantage of having a class is defeated
since I have to do the extra coding for each object that will be
created. It's like the class can only have a reference to the
movieclip outside itself, and not have a clip INSIDE that is fully
functioning. am I right about this? Is there someplace good I can
learn more about class objects and movieclip usage?
also, my class object IS a movieclip, but " this.getDepth() "
is meaningless inside the class object. hmmm...
This one works..... attaching the movies at the root level
(to a holder_mc)
// Frame 1
tmp1 =
holder_mc.attachMovie("someShape_mc","tmp1",holder_mc.getNextHighestDepth());
var BottomObject:ClassObject3 = new
ClassObject3(tmp1,100,150);
tmp2 =
holder_mc.attachMovie("someShape_mc","tmp2",holder_mc.getNextHighestDepth());
var topObject:ClassObject3 = new ClassObject3(tmp2,110,160);
// for the button add this:
Swap_btn.onRelease=function() {
BottomObject.swapIt(topObject);
trace("clicked button");
// ClassObject3.as
class ClassObject3 extends MovieClip{
var __LocalMovieClip:MovieClip;
function
ClassObject3(passedInMovieClip:MovieClip,x:Number,y:Number) {
trace(" this class object is at ["+this.getDepth()+"]");
__LocalMovieClip = passedInMovieClip;
__LocalMovieClip._x = x;
__LocalMovieClip._y = y;
public function swapIt(targetMc:MovieClip):Void {
trace("do the swap in the class");
trace("===========================");
trace("target type :" + typeof(targetMc));
trace("__LocalMovieClip type :" + typeof(__LocalMovieClip));
__LocalMovieClip.swapDepths(targetMc.__LocalMovieClip);
This one does NOT work..... attaching the movies within the
class object...
// Frame 1
var BottomObject:ClassObject2 = new
ClassObject2(holder_mc,100,150);
var topObject:ClassObject2 = new
ClassObject2(holder_mc,110,160);
// for the button add this:
Swap_btn.onRelease=function() {
BottomObject.swapIt(topObject);
trace("clicked button");
// ClassObject2.as
class ClassObject2 extends MovieClip{
var __LocalMovieClip:MovieClip;
function
ClassObject2(passedInMovieClip:MovieClip,x:Number,y:Number) {
__LocalMovieClip =
passedInMovieClip.attachMovie("someShape_mc","stuff1",passedInMovieClip.getNextHighestDep th());
__LocalMovieClip._x = x;
__LocalMovieClip._y = y;
public function swapIt(targetMc:MovieClip):Void {
trace("do the swap in the class");
trace("===========================");
trace("target type :" + typeof(targetMc));
trace("__LocalMovieClip type :" + typeof(__LocalMovieClip));
__LocalMovieClip.swapDepths(targetMc.__LocalMovieClip);
Maybe you are looking for
-
How to delete PDF files on an ASUS MemoPad
On an ASUS MemoPad there are files that the Adobe Reader can open that I want to delete. I connected the ASUS up to a computer to look at the ASUS file directory using WindowsExplorer. Some of the PDF files on the ASUS were found. But not all of them
-
Insert file to oracle db by C shell script
Hi, Could you pls help me how I can write script on C shell of Sun solaris to load data to Oracle database from text file with "," fields separator. Send me the samples script if can. Thanks you very much. Vu Tuan - Vietnam Mobile Telecom services co
-
No calendar in Gmail IMAP settings
I'm trying to get gmail imap calendar configured for a 3GS running 4.2. Under settings, mail/contacts/calendar it only has Mail and Notes under it. How do I add calendar? Thanks, Tim
-
Hi!, In My workbook i have defined totals on columns. They appear properly in the workbooks when viewed from the user edition, but when viewed from Viewer 3i, totals are not appearing. In preferences the attributes of total are set as default. Can an
-
Start BEX via RRMX doesn't work
Hello BW 3.5 /SAP GU 6.2 It is possible to access bex via system-> program-> BEx -> analyzer. However transaction RRMX doesn't start BEX . There is also no error message. But the EXCEL Process starts ( seen in the Windows Task Manager) and disappears