[Q] Re-Write Javascript to Actionscript 3
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [Q] Re-Write Javascript to Actionscript 3

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    3

    [Q] Re-Write Javascript to Actionscript 3

    Is there a table or a guide that i can use to get the equivelant code for JavaScript to ActionScript 3 at all? Doing a google search brings up a whole lot of bubcus in tearms of usefull information on the subject.

    If anyone knows of a table or anything of the like that would be great.

    DSD

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    665
    that should not be hard to figure out yourself :P e g let us take this js summary:
    PHP Code:
    function Cat(namecolor){
        
    /*
        Constructor: any code in here is run when the object is created
        */
        
    Cat.cats++;

        
    /*
        Private variables and functions - may only be accessed by private or privileged functions.

        Note that 'name' and 'color', passed into the Class, are already private variables.
        */
        
    var age  0;
        var 
    legs 4;
        function 
    growOlder(){
            
    age++;
        }

        
    /*
        Public variables - may be accessed publicly or privately
        */
        
    this.weight 1;
        
    this.length 5;

        
    /*
        Privileged functions - may be accessed publicly or privately
        May access Private variables.

        Can NOT be changed, only replaced with public versions
        */
        
    this.age = function(){
            if(
    age==0this.length+=20;

            
    growOlder();
            
    this.weight++;
        }
    }

    /*
    Prototyped Functions - may be accessed publicly
    */
    Cat.prototype = {
        
    talk:     function(){ alert('Meow!'); },
        
    callOver: function(){ alert(this.name+' ignores you'); },
        
    pet:      function(){ alert('Pet!'); }
    }

    /*
    Prototyped Variables - may be accessed publicly.
    May not be overridden, only replaced with a public version
    */
    Cat.prototype.species 'Cat';

    /*
    Static variables and functions - may be accessed publicly
    */
    Cat.cats 0
    In AS3, that could be something like:
    PHP Code:
    package {
        public class 
    Cat {
            private var 
    name:Stringcolor:uint;
            public function 
    Cat (name:Stringcolor:uint) {
                
    this.name namethis.cat cat;
            }
            private var 
    age:int 0legs:int 4;
            private function 
    growOlder():void {
                
    age++;
            }
            public var 
    weight:Number 1length:Number 5;
            public function 
    ageIt /* iirc naming this just "age" would conflict with var above */ ():void {
                if(
    age==0this.length+=20;

                
    growOlder();
                
    this.weight++;
            }
            public function 
    talk():void trace('Meow!'); }
            public function 
    callOver():void trace(this.name+' ignores you'); }
            public function 
    pet():void trace('Pet!'); }
            public var 
    species:String 'Cat';
            public static var 
    cats:int 0;
        }

    The mapping is not 1:1 but pretty close.

  3. #3
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    665
    ah, I missed Cat.cats++; in the constructor:
    PHP Code:
    public function Cat (name:Stringcolor:uint) {
                
    this.name namethis.cat catCat.cats++;
            } 

  4. #4
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Quote Originally Posted by realMakc View Post
    that should not be hard to figure out yourself :P e g let us take this js summary: -=- snip --
    Ok what im trying to achieve is to get this: Radar to display in flash. Either as a whole or as a 'projection' from the page itself. So i either want to know if its possible to recode this using AS3 or can i 'Project' it as a live feed of sorts to a swf file?

    DSD

  5. #5
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    665
    this link doesn't do much for me beyond looping several images. it requests jsoon data from this address, and there you can see actual image URLs. so it is just a matter of loading all these images into flash (using Loader or URLLoader class) and then swapping them on the screen every second. what I am saying is that here it is easier to replicate the behavior than to port javascript itself.
    Last edited by realMakc; 10-16-2013 at 06:49 AM.

  6. #6
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Quote Originally Posted by realMakc View Post
    this link doesn't do much for me beyond looping several images.
    Thats part of what the JS code does yes, but aside from looping the images i want to be able to utilize the scripts ability to automatically update the images to the next set without manual input.


    Quote Originally Posted by realMakc View Post
    it requests jsoon data from this address, and there you can see actual image URLs. so it is just a matter of loading all these images into flash (using Loader or URLLoader class) and then swapping them on the screen every second. what I am saying is that here it is easier to replicate the behavior than to port javascript itself.
    If it were that simple I wouldent have come here for help with this.. Ive researched alot of different approaches to this, but noone has an answer as to how i can either, replicate this or project whats on the page into a SWF file.

    I do appreciate the effort and help you are trying to provide.

    DSD

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

Poll by Flashkit.com