A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Classes?

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    NY
    Posts
    35

    Classes?

    How can i define a class like the Array class where you can assign values to a variatble directly and yet have it have functions attached to it.

    I want to be able to do this.

    myVar = 5;
    myVar.testOutput();

    //-----I want output to be
    5

    is this possible?
    thanks

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    not 100% sure on what you seek
    is it this -
    code:

    function testOutput(theVar){
    trace(theVar);
    myOutput.text = theVar;
    };

    myVar = 5;
    testOutput(myVar);



    hth

  3. #3
    Member
    Join Date
    Jan 2003
    Location
    NY
    Posts
    35
    no.. i want to create a class similar to that of the array class where you can assign values directly to the variable

    myVar = new Array();
    myVar = [1,2,3,4];
    myVar.push(5);

    I want to be able to do the same

    define a class with functions - maybe i'm using the wrong terms... maybe its not a class that i want to build - but i think that's what a collection of function is right?

    myVar = new myClass();
    myVar = 5;
    myVar.add(6);
    trace(myVar);

    //----output
    11


    did i make myself clearer now?

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    myClass = new Object();
    myClass.myVar = 5;
    myClass.myVar += 6;

    trace(myClass.myVar);

    you reached the limits of my approach to flash, so this might help

    http://www.macromedia.com/support/fl...del/index.html

  5. #5
    Senior Member
    Join Date
    Sep 2001
    Location
    Top Shelf
    Posts
    757
    possibly what your looking for...
    http://www.actionscript.org/tutorial...e/index2.shtml
    Inheritance is probably the hardest concept to understand in OOP for Flash.

  6. #6
    Member
    Join Date
    Jan 2003
    Location
    NY
    Posts
    35
    the add() function i added to the class was just to illustrate that i want to be able to add functions to a variable while still addressing it as a variable.

    Flash Arrays() have direct access
    myVar[5] = 6;
    Flash Arrays() have methods
    myVar.push(6);

    this is what i want to be able to do, so that

    myClass has direct access
    myVar = 5;
    myClass has methods
    myVar.someFunction(6);

    is that clearer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center