A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Using Maths Operators Stored in an Array

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Posts
    128

    [F8] Using Maths Operators Stored in an Array

    I have an array with the maths operators +, -, /, * stored like so:

    symbs[0] = "+";
    symbs[1] = "-";
    symbs[2] = "*";
    symbs[3] = "/";

    I have the following two numbers stored in variables:
    numb1 = 15
    numb2 =5

    I want to use add numb1 to numb2 using the addidion operator stored in the array address symbs[0].

    What line of code do I need to write to achieve this?
    (Using Flash 8)
    Many thanks!
    [swf width="300" height="40" background="#000000"]http://www.zizunetwork.com/zizunetworkcouk.swf[/swf]

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I don't know if you can do such a thing. What is your reasoning for this?

    The only example I can think of (there can be other methods) is this one:
    PHP Code:
    var symbs:Array = ["+","-","*","/"];
    var 
    numb1 15;
    var 
    numb2 5;
    var 
    res addNumbers(numb1,numb2,symbs[2]);

    trace(res);

    function 
    addNumbers(one:Number,two:Number,type:String) {
        switch(
    type) {
            case 
    "+":
                return (
    one two);
            break;
            case 
    "-":
                return (
    one two);
            break;
            case 
    "*":
                return (
    one two);
            break;
            case 
    "/":
                return (
    one two);
            break;
        };
    }; 

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Posts
    128
    Yea, that's similar to what I ended up doing.

    Cheers!
    [swf width="300" height="40" background="#000000"]http://www.zizunetwork.com/zizunetworkcouk.swf[/swf]

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