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




Identifying Custom Classes



Hello all.

What would be the best way to have a class instance be able to identify others of its class? Or figure out the class of any object?

All help is greatly appreciated.

-Brekk



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 08-14-2004, 01:28 AM


View Complete Forum Thread with Replies

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

Identifying Custom Classes
Hello all.

What would be the best way to have a class instance be able to identify others of its class? Or figure out the class of any object?

All help is greatly appreciated.

-Brekk

Custom Classes: One Class Tracks Multiple Other Classes?
I'm working on a coloring that allows kids to place objects on a scene and then color them so the image can be printed out. So assume you have sky background, the child can select a bird object, drag it into place and once they have it in place, color everything on the page (with a given palette of colors.)

So far it going great. However I want to track what objects have been added to the drawing on the fly. I have a potential solution using arrays but I'm thinking this is perfect opportunity to start using custom classes.

I'm thinking that I'd create a new instantiate a copy of the object class each time an object is added to the scene. However to track the objects added to the scene I'm thinking I'll also use an listing class to track them.

What I'm not sure about is the would the listing class simply contain an array of object identifiers? Any thoughts on the structure of the listing class?

I'm very new to oop as I've mainly been doing procedural programming up to this point but I'm eager to give this a shot.

Thanks!

Using Custom Classes Inside Of Custom Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?

P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!

Using Custom Classes Inside Of Custom Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?

P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!

Custom Events For Custom Classes
So what I'm trying to build is a custom class wich connects to a php socket server using an XML socket.
I don't know how I can broadcast an event so I can write something like the code below. Anyone can help ?







Attach Code

myClass= new myOwnClass();
myClass.onConnect=connectionHandler;

function connectionHandler{
//do something;
}

[CS3] Custom Classes
I'm not really sure what the problem is but I have been writing some classes for a card game and had them working fine using AS3, but because it seems easier to do other things with Smartfox Server using AS2 I've tried to get it going using AS2 with little success.

Here is the working AS3 code:

Card.as

Code:
package {
public class Card
{

private var suit:String;
private var number:String;
private var image:String;
private var isJoker:Boolean;
private var sortNumber:Number;
private var winNumber:Number;
private var Id:Number;

public function Card(number:String, suit:String, image:String)
{

this.suit=suit;
this.number=number;
this.image=image;
if (number == "Joker")
{
isJoker = true;
this.number = "Joker";
this.suit = "Joker";
}
else
{
isJoker = false;
}

}

public function printCard():String
{
if (!isJoker)
{
return "The " + number + " of " + suit;
}
else
{
return "The Joker";
}
}

public function getSuit():String
{
return suit;
}

public function getNumber():String
{
return number;
}

public function setSuit(suit:String)
{
this.suit = suit;
}

public function setNumber(number:String)
{
this.number = number;
}

public function setImage(image:String)
{
this.image = image;
}

public function setSort(sortNumber:Number)
{
this.sortNumber = sortNumber;
}

public function getSort():Number
{
return sortNumber;
}

public function setWin(winNumber:Number)
{
this.winNumber = winNumber;
}

public function getWin():Number
{
return winNumber;
}

public function setId(Id:Number)
{
this.Id = Id;
}

public function getId():Number
{
return Id;
}

}
}
Deck.as

Code:
package {
public class Deck {

private var cards:Array = new Array();
private var deckSize:Number;
private var gameType:String;

public function Deck(gameType:String) {

this.gameType=gameType;
var i:Number;

if (gameType == "500") {

for (i=4; i<=14; i++) {
if (i<=10) {
var newHeart:Card = new Card(String(i), "Hearts", "image");
var newDiamond:Card = new Card(String(i), "Diamonds", "image");
if (i > 4) {
var newSpade:Card = new Card(String(i), "Spades", "image");
var newClub:Card = new Card(String(i), "Clubs", "image");
}
}
if (i==11) {
var newHeart:Card = new Card("Jack", "Hearts", "image");
var newDiamond:Card = new Card("Jack", "Diamonds", "image");
var newSpade:Card = new Card("Jack", "Spades", "image");
var newClub:Card = new Card("Jack", "Clubs", "image");
}
if (i==12) {
var newHeart:Card = new Card("Queen", "Hearts", "image");
var newDiamond:Card = new Card("Queen", "Diamonds", "image");
var newSpade:Card = new Card("Queen", "Spades", "image");
var newClub:Card = new Card("Queen", "Clubs", "image");
}
if (i==13) {
var newHeart:Card = new Card("King", "Hearts", "image");
var newDiamond:Card = new Card("King", "Diamonds", "image");
var newSpade:Card = new Card("King", "Spades", "image");
var newClub:Card = new Card("King", "Clubs", "image");
}
if (i==14) {
var newHeart:Card = new Card("Ace", "Hearts", "image");
var newDiamond:Card = new Card("Ace", "Diamonds", "image");
var newSpade:Card = new Card("Ace", "Spades", "image");
var newClub:Card = new Card("Ace", "Clubs", "image");
}
cards.push(newHeart);
cards.push(newDiamond);
if (i>4) {
cards.push(newSpade);
cards.push(newClub);
}

}
var newJoker:Card = new Card("Joker", "Joker", "image");
cards.push(newJoker);

/*for (i in cards)
{
cards[i].setId(i);
}*/

deckSize = cards.length;

}
}

public function printDeck():String {
var deckString:String;
var i:Number;
for (i=0; i<cards.length; i++) {
if (i != 0) {
deckString = deckString + " " + cards[i].printCard();
} else {
deckString = cards[i].printCard();
}
if (i<(cards.length-1)) {
deckString += ",";
}
}
return deckString;

}

public function deal(hands:Array)
{
if (gameType == "500")
{
var i:Number, j:Number;
var tempCard:Card = new Card("","","");
var hand1:Hand = new Hand("500");
var hand2:Hand = new Hand("500");
var hand3:Hand = new Hand("500");
var hand4:Hand = new Hand("500");
var kitty:Hand = new Hand("500");

hands.push(hand1);
hands.push(hand2);
hands.push(hand3);
hands.push(hand4);
hands.push(kitty);

for (i=0; i<10; i++)
{
for (j=0; j<4; j++)
{
tempCard = cards[0];
hands[j].addCard(tempCard);
cards.shift();
}
}
for (i=0; i<3; i++)
{
tempCard = cards[0];
hands[4].addCard(tempCard);
cards.shift();
}
}
}

public function shuffle()
{
var i:Number;
for (i=0; i<100; i++)
{
var randCard:Number;
randCard = Math.floor(Math.random() * (deckSize));
var tempCard:Card = new Card("","","");
tempCard = cards[randCard];
cards.push(tempCard);
cards.splice(randCard,1);
}
}
}
}
Hand.as

Code:
package {

public class Hand {

private var cards:Array = new Array();
private var handSize:Number = 0;
private var gameType:String;
private var hasHearts:Boolean, hasDiamonds:Boolean, hasClubs:Boolean, hasSpades:Boolean;

public function Hand(gameType:String) {

this.gameType=gameType;

}

public function printHand():String {
var handString:String;
var i:Number;
trace(cards.length);
for (i=0; i<cards.length; i++) {
if (i != 0) {
handString = handString + " " + cards[i].printCard();
} else {
handString = cards[i].printCard();
}
if (i<(cards.length-1)) {
handString += ",";
}
}
return handString;
}

public function addCard(inCard:Card)
{
cards.push(inCard);
handSize = handSize + 1;
}

public function getCardSuit(numCard:Number):String
{
return cards[numCard-1].getSuit();
}

public function getCardNumber(numCard:Number):String
{
return cards[numCard-1].getNumber();
}

public function getCard(numCard:Number):Card
{
return cards[numCard-1];
}
}
}
testAS3.fla

Code:
import Card;
import Deck;
import Hand;

var deck:Deck = new Deck("500");
var hands:Array = new Array();
deck.shuffle();

deck.deal(hands);

trace("Hand 1: " + hands[0].printHand() + "
")
trace("Hand 2: " + hands[1].printHand() + "
")
trace("Hand 3: " + hands[2].printHand() + "
")
trace("Hand 4: " + hands[3].printHand() + "
")
trace("Kitty: " + hands[4].printHand() + "
")
To move to AS2 I got rid of the package and public before class, and this seemed to work ok with one hand object, one deck object but when I had more than one it seemed to connect them and so if I added a card to a hand object and then added a card to a different hand object, both hand objects would have both cards. Very weird.

Any ideas on what else might need to be changed between AS3 and AS2 that could be causing this problem?

Custom Classes
I have a project due and I am very confused about what I am doing. Here is the assignment

http://nlecommerce1.dcccd.edu/instru.../Project_3.htm

My main questions are how do I send the spaceship in a random direction? And although I am vaguely familiar with custom classes, I have not done one for buttons and I am not sure how to get started on the one for this project.

Thank you for any and all help!

Custom Classes
hey, i was in my actionscripting class at school and my teacher metioned that there were custom made classes or effects or something that i could import into flash using actionscrit like

import MX.Classes.Effects.*

or something like that anyway
but anyway, if you happen to know where i could find some or if they even exist and/or are worth my time please let me know, if there's anything really important or really cool PM me

Custom Classes
Hello. I am having some trouble with making a custom class in flash. I have made a new class. Let's call it "NewClass". I need my program to have many TextInput boxes but I also need each box to contain more information about itself so I made this "NewClass" extend TextInput. I am now having trouble actually making the instances of this class on the stage. I tried declaring an object of the type "NewClass" and then setting x and y positions and things like that but I cannot get it to work. Also is there any way that I can just make the TextInput boxes manually and then in my code just change them to my "NewClass" so that they have the new features but still retain all of the characteristics of TextInput. Basically I need a way of having TextInput boxes on the stage and having them keep track of some information about themselves that flash does not provide already so I need to have them contain some type of private data member. I hope that this question is not too confusing. I am used to programming with C++ and am not very experienced with ActionScript yet. Thanks in advance for any help.

CS3 - Can't Use Custom Classes
I'm trying to use a custom class I've created in Actionscript 3.0 for Flash 9 (CS3) and I keep getting the following compile time error messages where I try to create a new instance of the class:

1046: Type was not found or was not a compile-time constant: ScrollView.
1180: Call to a possibly undefined method ScrollView.

I've looked at the Adobe documentation online at: http://livedocs.adobe.com/flash/9.0/....html#wp119105
and from what I can see I'm doing everything correctly - it just doesn't work.

I've cleaned all but the absolute bare essentials out of the actionscript file and created a new .fla file that does nothing except call the object's constructor to remove any weird interactions my other code may be causing, but I still get the same errors every time.

My actionscript file is located in a directory called tlc, which is a subdirectory of a directory called MyC, which is a subdirectory of a directory called com which is located in the same directory as my .fla project source files. (Standard package directory structure).

My actionscript file is:

Code:
package com.intel.tlc {
import flash.display.Sprite;
class ScrollView extends Sprite {
public function ScrollView() {
trace ("Success");
}
}
}
As you can see, nothing too fancy. In my .fla's one and only frame I have nothing but the following actionscript:


Code:
import com.intel.tlc.ScrollView;

var sv:ScrollView=new ScrollView();
Can anyone see what it is I'm missing or doing wrong here?

Thanks.

Custom Classes
Hey guys, I need a little help here. I'm creating a custom class that will handle submenu creation for the navigation menu I am working on. The class code is attached. For whatever reason, I can't figure out why the text fields aren't showing up. The end of the for loop is being reached and being confirmed by the trace action. If you don't mind, take a look and see if you can help me figure this one out.

Mike









Attach Code

class SubMenu {

// Movie Clip to contain the visuals of the menu.
private var container_mc:MovieClip;

/*
* Constructor
*/

public function SubMenu(x:Number, y:Number, target:MovieClip, mItems:Array, depth:Number) {

// create the container clip
container_mc = target.createEmptyMovieClip("submenu", depth);

// Create the text fields
drawText(mItems, container_mc.submenu);

// Initialize position
setX(x);
setY(y);
}


/*
* Accessors to assign and get container_mc x
*/

public function setX (x:Number):Void {
container_mc._x = x;
}

public function getX ():Number {
return container_mc._x;
}

/*
* Accessors to assign and get container_mc y
*/

public function setY (y:Number):Void {
container_mc._y = y;
}

public function getY ():Number {
return container_mc._y;
}


/*
* Add text fields to our submenu
*/

public function drawText(mItems:Array, target_mc:MovieClip) {
for( var i = 0; i < mItems.length; i++) {

// Create the text field
target_mc.createTextField(mItems[i]+"_txt", target_mc.getNextHighestDepth(), 0, 0, 200, 200);

// Create the formatting rules
target_mc[mItems[i]+"_txt"].text = mItems[i];
target_mc[mItems[i]+"_txt"].selectable = true;

var txt_fmt:TextFormat = new TextFormat();
txt_fmt.color = 0xFF0000;
txt_fmt.size = 12;
target_mc[mItems[i]+"_txt"].setTextFormat(txt_fmt);
trace("Drawing: "+ mItems[i]);
}
}
}

Help With Custom Classes
hi,
im am fairly new to actionscript and flash. i am trying to learn how to work with custom classes. I understand how to right them( i think ), but i dont understand how to import them into an fla file. just to make sure can u also tell me if this is the right way to write them.

package{
class myClass{

//define methods and properties

}
}
thanks






























Edited: 08/04/2008 at 04:40:24 PM by Jerome Squalor

Custom Classes, Help
hi every one,
i really need help with custom classes, i just dont understand how to work with them. Can someone give me a small tutorial on how to write them, where to save them, and how to use them in another file.

thank you very much

Custom Classes
Could somebody please tell me how to go about creating custom classes or editing built-in ones (such as the Math class). I want to have easier access to some equations that I commonly use. Is this possible or will I have to continue creating new functions?

For...in And Custom Classes
Is it possible to use a for...in loop with a custom class and access it's public properties? eg;


Actionscript Code:
var myClassInstance:myClass = new myClass(0,'someArg','etc'); 
for (var i:String in myClassInstance) {         trace(myClassInstance[i]);}

I've tried to test this myself but am having no luck due to some problems elsewhere in my code, so it's hopefully quicker to just ask.

Thanks a lot,

Jamie

Using Custom Classes
Lee shows in his tutorial to change your actionscript preferences to point to your specific directory while coding. Its seams to work fine till you upload your swf to the web. Is this because it loses your .as files and classes when you don't upload. If so why not just make a directory copying classes you need in your flash files for example.

as/mosessupposes.as

and just put the .fla in the same directory. It seams like using lees method is great for testing but for uploading etc it really sucks. I don't know.
Help me understand!

Custom Classes
I'm sure there has been much information about creating your own classes, but I was curious as to where, and a few small questions I have about them.

1. Why create custom classes?
2. Is this best practice for Senior Flash Developers?
3. Should a Jr. Flash Developer understand and have the ablility to create custom classes? (I'm sure it wouldn't hurt, but is it nessasary?)
4. Scale of 1 to 10, what is the difficulty in learning and understanding custom classes?

I hope this is the right forum for this question, if not mod's please put it where you feel it should go. Lastley, Thanks in advance!

ZG

Buttons And Custom Classes
Hey everyone!

I'm a new member to the forums with an annoying Flash MX 2004 problem. I was wondering if you people could help me out?

Basically I'm trying to get a button to change color via a Custom class written in ActionScript. I have built and attached an example to show you all what I'm trying to achieve. The code works perfectly with a MovieClip, but when I try to apply it to a Button, it falls flat (can't even find the reference to the button it seems).

On my stage are two objects:
1. A Movie Clip
2. A Button

These are both set to "Export for ActionScript", and have an attached class called 'ColorClass'. ColorClass is basically what does all the work (makes a Color object, and has set and get methods). I also have an action layer where all my other code is contained.

I'm fairly new to ActionScript, but come from a Java background, so know a bit about code :P Hopefully this is a simple problem where I just overlooked something obvious!

Thanks in advance,
Damask

Scope Of Custom Classes
MX Pro 2004

I have a MainMovie that loads several external swf files at runtime via MovieClipLoader.

The MainMovie has a few custom classes, that do work fine when called from within the MainMovie. The custom classes are able to manipulate the loaded MCs, i. e. the MCs are in the scope of the custom classes. I hoped the same for the other direction, but . . .

I tried many ways of calling the custom classes of the MainMovie from within the loaded MCs without success; _root, _global, classObject.
The only way was to include the classes in every one of the MCs = redundant code = bad.

How can I call these classes from within the MCs loaded at runtime?

Custom Events In Classes
I want my class called Duck to have an event called finish talking, so that in the fla I can have something like this:

Code:
import Duck;
var dd:Duck;
dd.onFinishTalking = function()
{
//Do stuff
}

How would I code this into my fla. I found the event keyword but I couldnt find the helpdocs in Flash Help files

SetInterval In Custom Classes
I'm trying to use setInterval in a custom class without success. I've been doing some research about this, and apparently, it's been a commonly recognized problem.

Some threads within this forum have claimed to have solved this problem, but when I've tried the examples that were given, they've either failed or little explanation was given to explain what is needed to get them functioning.

Here is an example of a thread that, allegedly, solves the setInterval problem within a class.

FlashGuru's Solution

Can anyone help me with this? All that I want to do is to call or create a setInterval function that will allow enough time to pass so that I can access properties of my MovieClip object.

Custom Classes With [ ] Notation
Hey,

I am writing a class (this is the first time I write a class) where I need to create a dynamic array to be used within the class. Well, I am an extensive user of the [ ] notation, but dont know how to figure this out.

The problem is simple:

code:
class Test {

function createDynamicArray(arraynumber)
{
// normally I would do that:
_root["myarray"+arraynumber] = new Array();

// but I want the array visible just in the class and not in the entire scope
// then I tried
this["myarray"+arraynumber] = new Array();

// but then it's visible just in this function and not in other class functions
// completely desperated, I tried:
["myarray"+arraynumber] = new Array();
// it didnt work either and gave me an error - as expected.
}
}


Any clues???

GetChild With Custom Classes
I am using the new add/getChild methods with a custom class (that extends MovieClip) and am having some problems. I addChild without problem, but when i need to update the MC using a method of the custom class, I do a
Code:
getChildAt(i).myUpdateMethod("new text");

and the compiler yells at me about Type error. I know the getChildAt method returns a DisplayObject, but I don't seem to be able to cast to my object type. Is there a better way of doing what I'm trying to do?

[CS3] Custom Components & Classes
Does anybody know where i can start learning about making custom classes and components? I've had a look around and theirs minimal sources so i was wondering if anybody on here knew where i could learn the basics and beyond!

Thanks in advance

Custom Classes Question
I've just begun to get into custom class programming. My question is this I have created a .as file. And it the menu edit/preferences set the classpath to the folder with my .as file. Should I get a codehint for it? Like when I type

ActionScript Code:
var hmm: //(should a code hint pop up with my class?) like so
var hmm:MyClass
Or am I not understanding this correctly?

Creating Custom Classes
Hey guys,

I'm building a text game, and I want to create a some custom objects. How can I build a custom class? I've never done so before...

Thanks!

-theonlycarmire

First Shot At Custom Classes.
Trying to learn how to make custom classes. Just want to have two functions from the class. One to fade a mc(circle_mc) out and another to fade it back in again. I can get the class to trace to the fla file but can't get the movieclip to tween at all. Any help on this would be greatly appreciated.


import mx.transitions.Tween;
import mx.transitions.easing.Regular;
import mx.transitions.easing.Strong;

==================class file====================

class BallClass extends MovieClip {


private var _mcFade:MovieClip;
private var _tweener:Tween;



public function get mcFader() {
trace("getting....")
return _mcFade;

}

public function set mcFader(mcFade:MovieClip) {
trace("setting...")
_mcFade = mcFade;

}



public function fadeOut(mcFade:MovieClip) {
this._alpha = 0;
trace("fadeout");
}



public function fadeIn() {
this._xscale = 500;
trace("fadein");

}


}

==================fla file====================

var ballTest:BallClass = new BallClass();
trace(ballTest.mcFader);

ballTest.mcFader = circle_mc;
trace(ballTest.mcFader);

circle_mc.onRollOver = function () {
ballTest.fadeOut(circle_mc);
}

circle_mc.onRollOut = function () {
ballTest.fadeIn(circle_mc);
}

LoadVars And Custom Classes
Just a quick qustion, Im tying to make a custom class that provides alogin functionality by providing a username and password ie:


Code:
//Last Update: Thur 23 Feb 06
class systemUser {
// Declare Variables
public var email:String;
public var pword:String;
public var uid:Number;
public var fname:String;
public var lname:String;
// Constructor
public function systemUser(email:String, pw:String) {
}
// Login Function
public function login() {
var user_lv:LoadVars = new LoadVars();
user_lv.onLoad = function(success:Boolean) {
if (success) {
email = user_lv.userEmail;
pword = user_lv.userPassword;
uid = user_lv.userID;
fname = user_lv.userFirstName;
lname = user_lv.userLastName;
}
};
user_lv.useremail = email;
user_lv.pword = pw;
user_lv.sendAndLoad("scripts/login.php", user_lv, "POST");
}
public function returnName():String {
return fname+" "+lname;
}
//eof
}
The above code works great on the Flash timeline but I cant seem to get the LoadVars to connect to PHP to query the mysql db while its in this custom class. Is it possible?

Many Thanks.
Ant

Madness With Custom Classes
Hi all,

The strangest Flash behavior is driving me near to utter madness. I am working on an application with a few custom classes. Everything worked fine for many weeks. Yesterday, I quit Flash, and upon reopening my FLA, none of the custom classes would link in. I got the error "The class or interface <xxx> could not be found."

After hours of banging my head, I tried something simple. I created a new .fla called test.fla. I created a layer called Actionscript. I added the following code to the first frame of the Actionscript layer:

var test:ImportTest = new ImportTest();

I then, in the exact same directory as the file test.fla, created a file called ImportTest.as. This file has the following contents:

class ImportTest {
public function ImportTest() {
trace("Instantiation.");
}
}

When I execute this test.fla, I get the error:

**Error** Scene=Scene 1, layer=Actionscript, frame=1:Line 1: The class or interface 'ImportTest' could not be loaded.
var test:ImportTest = new ImportTest();

Total ActionScript Errors: 1 Reported Errors: 1

What gives? Perhaps a classpath issue? Well, my global classpath has:

.
$(UserConfig)/Classes
$(LocalData)/Classes

The dot alone should be enough.

My document classpath has:
.

Perhaps it's a permissions problem? Doubtful. The directory listing is:
-rw-r--r-- 1 Richard Richard 85 Feb 22 14:35 ImportTest.as
-rw-r--r-- 1 Richard Richard 41472 Feb 23 09:47 test.fla

I'm using Actionscript 2.0 in Flash 8 on a Mac OS X 10.4.

Like I said, this all worked perfectly well just moments before. I quit Flash to install some Mac OS X updates (the sorts of standard updates that Apple pushes out from time to time - in this case they were updates to support changes in Daylight Savings Time), restarted the computer, opened Flash, and I can no longer seem to include any external actionscript files.

Any ideas? I am at the end of my rope on this one, ready to jump off a bridge!! I've attached the code for your reference....

Thanks,
rj_resnick







Attach Code

-rw-r--r-- 1 Richard Richard 85 Feb 22 14:35 ImportTest.as
-rw-r--r-- 1 Richard Richard 41472 Feb 23 09:47 test.fla

How To Tween CUSTOM Classes?
I am familiar with the tween class but all I want to do is add its functionality to my custom classes which are nothing more than extensions of the Movie Clip class....

I cant use the import statement in a class file and putting it on the main stage doesnt work either...

Any ideas?

Help: EventDispatcher Vs. On...() In Custom Classes
Hi,

I'm starting to create an application where I have a symbol+class that works like a button, and I'm using ActionScript 2.0.

Now I need to implement event handling for its click.

I understand how to do this using the EventDispatcher class, but I'd like to do something simpler.

Instead, I'd like to be able to use the "myButton.onWhenClicked = function() { ...eventcode... }" event syntax, just like some of the older Flash elements. (It will cut down on my lines of code, and I never need to assign multiple functions to the same event.)

Yet when I try to do this, I get a compile-time error if I don't include the onWhenClicked() function as a class member. If I do include it (with a blank body), and then try to reassign it from code outside of the class ("myButtonInstance.onWhenClicked = ...") it doesn't work.

Is it possible to use the on...() event system with custom classes, or is EventDispatcher the only way?

Thanks
Michael

Arrays In Custom Classes
The class below is in a document called (Node.as)

class Node {
private var _z = new Array();
public function Node(z) {
this._z[0] = z;
}
function getz(index) {
return this._z[index];
}
}

This is the actionscript of the main document

import Node;
//create line placeholders
var node0:Node = new Node(234);
trace(node0.getz(0));
var node1:Node = new Node(345);
trace(node0.getz(0));
var node2:Node = new Node(786);
trace(node0.getz(0));

Why does the trace yield completely different numbers?????

[FMX] Buttons And Custom Classes
Hey everyone!

I'm a new member to the forums with an annoying Flash problem. I was wondering if you people could help me out?

Basically I'm trying to get a button to change color via a Custom class written in ActionScript. I have built and attached an example to show you all what I'm trying to achieve. The code works perfectly with a MovieClip, but when I try to apply it to a Button, it falls flat (can't even find the reference to the button it seems).

On my stage are two objects:
1. A Movie Clip
2. A Button

These are both set to "Export for ActionScript", and have an attached class called 'ColorClass'. ColorClass is basically what does all the work (makes a Color object, and has set and get methods). I also have an action layer where all my other code is contained.

I'm fairly new to ActionScript, but come from a Java background, so know a bit about code Hopefully this is a simple problem where I just overlooked something obvious!

Thanks in advance,
Damask

Extending Custom Classes In AS3?
im trying to port my code to as3 but i stumbled on a problem i have no idea how to fix.
error report:

Code:
verify PointAirFri$iinit()
stack:
scope: [global Object$ Point$ PointAirFri$]
locals: PointAirFri Number Number Number
0:getlocal0
stack: PointAirFri
scope: [global Object$ Point$ PointAirFri$]
locals: PointAirFri Number Number Number
1:pushundefined
stack: PointAirFri void?
scope: [global Object$ Point$ PointAirFri$]
locals: PointAirFri Number Number Number
2:setslot 14
stack:
scope: [global Object$ Point$ PointAirFri$]
locals: PointAirFri Number Number Number
4:abs_jump 78424138 45
stack:
scope: [global Object$ Point$ PointAirFri$]
locals: PointAirFri Number Number Number
0:getlocal0
stack: PointAirFri
scope: [global Object$ Point$ PointAirFri$]
locals: PointAirFri Number Number Number
1:pushscope
stack:
scope: [global Object$ Point$ PointAirFri$] PointAirFri
locals: PointAirFri Number Number Number
2:getlocal0
stack: PointAirFri
scope: [global Object$ Point$ PointAirFri$] PointAirFri
locals: PointAirFri Number Number Number
3:constructsuper 0
VerifyError: Error #1063: Argument count mismatch on Point$iinit(). Expected 3, got 0.
at PointAirFri$iinit()
at docClass/::init()
at docClass$iinit()
this is how the defined the classes:


Code:
package{
public class Point
{
vars
public function verlet(a)
{
code
}
public function savePoint()
{;
code
}
public function restore()
{
code
}
public function Point(__x:Number, __y:Number, __fr:Number)
{
x = __x;
y = __y;
dx = 0;
dy = 0;
vx = 0;
vy = 0;
friction = __fr;
}
}
}

package{
import Point;
public class PointAirFri extends Point
{
private var airFriction;
public override function verlet (a)
{
code
}
public function PointAirFri(__x:Number, __y:Number, __afr:Number)
{
x = __x;
y = __y;
dx = 0;
dy = 0;
vx = 0;
vy = 0;
airFriction=__afr;
}
}
}

if anyone has any idea why that error happens please enlighten me

Importing Custom A.S Classes
Hello peeps, I am getting confused about importing custom classes into Flash 8. What exactly are the steps to go about doing it?
And once it's integrated, it's there forever?

Don't mind me for asking this, I am trying hard to pick up flash.

Including Custom Classes
Hello Kirupians,

I have a few custom classes stored in AS files. Is it possible to have these classes imported another way from using the following method:

Code:
import ClassFile;
I want to have the AS files loaded from a server (policy file created for inter-domain talk) into to flash. Also I want it to work, lets say if a person downloads the main SWF and plays it on their compy, i want the class files to be loaded from http://xyz.com/ClassFile.as and so on.

Any way to do this?

Importing Custom Classes
Okay I am having an issue getting my custom made classes imported to the flash movie. It seems to ave a problem importing (or using) the class. Here is the as code I am attempting to use to import and call to a function inside of a class:


Code:
import form_classes.as;
var Contr:Controller = new Controller("testt");
It always pops up an error of

Code:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: The class or interface 'Controller' could not be loaded.
var Contr:Controller = new Controller("testt");
Total ActionScript Errors: 1 Reported Errors: 1
and I am not sure why. So if anyone could help me out here that would be great.

Where Do I 'install' Custom Classes?
Hey guys,

I've never used custom classes before ...and stumbled accross this:
http://blog.greensock.com/tweenfilterliteas2/

It looks really usefull and I really wana play with it! - How do I go about installing the class?

Very noobish i know ...help much appreciated

Why I Have To Import Custom Classes
Code:

package {
import flash.display.*;
import example.test.Main;

public class Document extends MovieClip {
function Document() {
new example.test.Main();
}
}
}
it doesnt work without the 2nd import (import example.test.Main)
why is it so?

Events In Custom Classes
Ok I finally realize that I don't understand how the EventDispatcher works.
Or, perhaps, not fully understands it anyway.

My problem:
I've created a custom class, lets call it Bounce. Everytime the ball hits the ground it broadcast the event Event.CHANGE as so:

Code:
disp.dispatchEvent(new Event(Event.CHANGE));
Where disp is a EventDispatcher created when the class Bounce first is created.

Everything works great if I have once Bounce class object on the main timeline, if I add another one the CHANGE for the first one stops triggering but the last one added works instead.


Code:
var bouncyBall:Bounce = new Bounce();
var bouncyBall2:Bounce = new Bounce();

bounceyBall.addEventListener(Event.CHANGE, handler); // this works now

bounceBall2.addEventListener(Event.CHANGE, handler); // after this line one bounceBall2 responds to the Event.CHANGE
Any clues what misstake I'm doing?

[noob] How To Use Custom Classes?
My document class:


ActionScript Code:
package {    import math.mathFuncs;    import flash.display.MovieClip;    public class project extends MovieClip {        public function project () {            var myArea:area = new area();            trace(myArea(2,5));        }    }}
My math class:

ActionScript Code:
class math.mathFuncs {    static function area(l:Number, h:Number) {        return l*h;    }}
How would I use the area function from my master document class?

Custom Classes Communication
do you communicate among a 2nd or more level of classes?

Lets say I have this Main.as, I imported in Logo.as. And I have this Shadow.ac classes that I wanted to apply on to several classes too.

Main.as
ActionScript Code:
package {
import flash.display.MovieClip;
import classes.*;

public class main extends MovieClip {
public var logo:FlashBlogLogo = new FlashBlogLogo();
public var dropShadowropShadow = new DropShadow();

public function main():void {
addChild(dropShadow);
addChild(logo);
}
}
}



Logo.as
ActionScript Code:
package {
import flash.display.MovieClip;
import classes.*;
import fblog_logo;

public class Logo extends MovieClip {
public function Logo():void {
public var dropShadowropShadow = new DropShadow();
var fb_logo:fblog_logo;
fb_logo = new fblog_logo();
addChild(fb_logo);

trace("FlashBlogLogo loaded");
fb_logo.filters=new Array(dSF); **shadow applied

}
}
}



DropShadow.as
ActionScript Code:
package {
import flash.display.MovieClip;
import flash.filters.DropShadowFilter;
public class DropShadow extends MovieClip {
public function DropShadow():void {

var dSFropShadowFilter = new DropShadowFilter();

dSF.color=0x000000;
dSF.blurX=5;
dSF.blurY=5;
dSF.angle=2;
dSF.alpha=.6;
dSF.distance=2;

//fb_logo.filters=new Array(dSF); ** or should I applied here?

}
}
}



If I put it all under 1 as file, it would be no problem detecting the target, but now I'm separating the classes and loading all into "main.as", how could 1 communicate with other classes without having to put it all together?

Issues With CS3 And Custom Classes Please Help
I’m having issues with the Custom Class tutorial on the website. I’m trying the “Advanced Filter Effects” tutorial I followed all the steps and even downloaded the files to compare what I have and it matches up. But when I export my movie I get an error, for example when I open the afe_start.fla file and export I get an error SEE the image below.

I have doubled check to make sure the .as file is in the correct directory and it is...

Under my Flash Preferences I have pointed my ASC 3 setting to:
C:Documents and SettingsFivepixDesktopActionscript

And in my flash I have the following:
Code:

import com.caurina.transitions.*;

var ai:Ai = new Ai();
addChild(ai);

function mover():void
{
   Tweener.addTween(ai, {x:Math.random()*550,
   y:Math.random()*400,
   rotation:Math.random()*400,
   time:1,
   onComplete:mover});
}

mover();

Please note I added the “com. " In my import because inside the Actionscript folder I created a folder called “com” & placed the caurina folder inside of it

Is there something I missed? Or a setting I need to double check please let me know. (I’m using Flash Professional CS3)

How To Create Custom Classes In AS3?
Hey!

Could really use some help here. I want to create some custom classes, like the ones in the Custom class tutorial here, but I want it to work in AS3, and I can't figure it out...

Can anyone post a simple example of a class in an AS file, and the code in the fla file?

Thank you in advance

Piblishing SWF With Custom Classes
Someone correct me if I am wrong. I have downloaded a Class from ( http://www.betriebsraum.de/ AKA QueueLoader in downloads ) used the Extension manager to install the file in Flash 8.

Now I can ctrl + enter and test the fla, everything works just fine. I can double click on swf and everything works. But when I upload the swf to my server the class does not work. I am thinking I need to upload the class files too? But where does te Extension Manager stores them? This is my first time using classes. So be gently with me.

Any Help would be good.

Code Hints With Custom Classes ?
Start using MX 2004 for few weeks now...


I was wandering how do I get code hints to appear when I'm using my custom classes??

Mx2004 Constructor In Custom Classes
ok i have adopted the new way of doing things. but i havent managed to translate the way i do things completely into as2.0

basically i instantiate a mc with:

attachMovie("leftHandMC", "leftHand", _level0.getNextHighestDepth());

in the linkage box properties for the movieclip "leftHandMC" i have linked it to the class LeftHand and that works fine. The class compiles etc. My problem is that I have no idea how to pass anything to the LeftHand constructor! Does anyone know a better way?

Cheers
Simon.

[CS3] Custom Classes And A Strange Problem...
Hi,

I'm experimenting with custom classes and trying to extend the pre-built classes...

I found tutorials and followed them and i could successfully wrote my own custom class derived from Math class...

My question is, i found another custom class from google and tried to integrate that one into my fla using the correct class path. but whenever i test the movie or check the code it gives this error "... class or interface could not be loaded..." see the bold text at the bottom...

this one is a custom class which extends the MovieClip...



PHP Code:




class Rectangle extends MovieClip {

  

  // Declare the nested instance
  // as a property.
  private var mcShape:MovieClip;

  function Rectangle() {
    trace("A Rectangle");
  }

  public function setDimensions(nWidth:Number,
                                nHeight:Number):Void
  {
    
    // Since you've declared mcShape as a
    // property, you can then reference it.
    mcShape._width = nWidth;
    mcShape._height = nHeight;
  }

}







a rectangle movieclip with a linkage of myRectangle and class id = Rectangle sits in the library for runtime...

is there something that i should be aware of with "extending prebuilt classes" approaches ?


since i can build my own class Makearandom without problems and my classpath settings are ok in the prefs...

But that particular one only works when the Rectangle.as resides in the same folder with the fla... I ask this just because to have full knowledge of the fundamentals about custom classes...



ANY IDEAS?

Accessing Variables Within Custom Classes
I've created a number of custom classes that I'm putting together in a separate swf file. In those classes I am creating public variables such as arrays that I would like to be able to access from the main timeline.

Can anyone tell me how I can do that (or IF I can do that)?

Thanks,

Okay, nobody seemed to wanna bite on the original post so let me try and expand my question:

Here is my class:


Code:
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.AntiAliasType;
import flash.text.TextFieldAutoSize
import fl.controls.ComboBox;
import fl.controls.TextInput;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.controls.CheckBox;

public class myPrefForm extends Sprite
{
public var prefcheckX:Number = 10;
public var prefcheckY:Number = 0;
public var prefcb:CheckBox;
public var itemCount:Number = 1;
public var myPrefArray:Array = new Array();
public function myPrefForm(XMLData):void
{
trace(XMLData);
var lblFormat:TextFormat = new TextFormat();
lblFormat.font = "Tahoma";
lblFormat.size = 12;
lblFormat.bold = true;
lblFormat.color = 0x000000;
lblFormat.align = "right";

var fieldFormat:TextFormat = new TextFormat();
fieldFormat.font = "Tahoma";
fieldFormat.size = 12;
fieldFormat.color = 0x000000;
fieldFormat.align = "left";

for each (var pref:XML in XMLData.userPref)
{
prefcb = new CheckBox();
prefcb.label = pref.prefTitle;
prefcb.textField.autoSize = TextFieldAutoSize.LEFT;
prefcb.textField.embedFonts = true;
prefcb.setStyle("textFormat", fieldFormat);
if (pref.prefSelected == "True") {
prefcb.selected = true;
myPrefArray.push(pref.prefID);}
prefcb.x = prefcheckX;
prefcb.y = prefcheckY;
prefcb.name = pref.prefID;
prefcb.addEventListener(MouseEvent.CLICK, addPref);
addChild(prefcb);
prefcheckY += 20;
if (itemCount == pref.rowMax) {
itemCount = 0;
prefcheckY = 0;
prefcheckX += 200;
}
itemCount ++;
}
function addPref(e:MouseEvent):void {
if(e.target.selected) {
trace("adding to array");
myPrefArray.push(e.target.name);
} else {
for (var p:int = 0; p < myPrefArray.length; p++) {
if (myPrefArray[p] == e.target.name) {
myPrefArray.splice(p,1);
}
}
}
}
}
}
}


on the parent clip I have the following code to instantiate this instance of myPrefForm:


Code:
myPref = new myPrefForm(prefDataXML);
myPref.x = 0;
myPref.y = 265;
addChild(myPref);


As the user checks or unchecks preferences, the array (myPrefArray) is updated accordingly. I have a save button on the parent clip that will save everything to a sql database but it needs to know the value of myPrefArray which only seems to exist in the myPrefForm class and I cannot figure out how to reference it on the parent.

PLEASE HELP!!

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