dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: How to convert AS2 - 3

Hybrid View

  1. #1
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363

    Post How to convert AS2 - 3

    I have this dynamic news updater that I need to be AS3. Any ideas?

    Code:
    function loadMyText(evt)
    {
        var _loc2 = new LoadVars();
        _loc2.load("content.html");
        _loc2.onLoad = function (success)
        {
            if (success)
            {
                my_txt.text = this.content;
                my_title.text = this.title;
            }
            else
            {
                trace ("Could not load text file.");
            } // end else if
        };
    } // End of the function
    this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
    my_sb.setScrollTarget(my_txt);
    my_sb.setSize(16, my_txt._height);
    my_sb.move(my_txt._x + my_txt._width + 5, my_txt._y);
    loadMyText();
    var flash_css = new TextField.StyleSheet();
    flash_css.load("styles.css");
    my_txt.styleSheet = flash_css;

  2. #2

  3. #3
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    This is what I have come up with so far but I still get a few errors on lines 7 and 14. What do you think?

    Code:
    package  { 
    	function loadMyText(evt)
    	import flash.text.TextField;
    	{
    	    public var _loc2 = new LoadVars();
    	    _loc2.load("content.html");
    	    _loc2.onLoad = public function (success)
    	    {
    	        if (success)
    	        {
    	            my_txt.text = this.content;
    	            my_title.text = this.title;
    	        }
    	        else
    	        {
    	            trace ("Could not load text file.");
    	        } // end else if
    	    };
    	} // End of the function
    	this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
    	my_sb.setScrollTarget(my_txt);
    	my_sb.setSize(16, my_txt.height);
    	my_sb.move(my_txt.x + my_txt.width + 5, my_txt.y);
    	loadMyText();
    	var flash_css = new TextField.StyleSheet();
    	flash_css.load("styles.css");
    	my_txt.styleSheet = flash_css;
    }

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    This will load the text, you can add the rest:
    PHP Code:
    package {
        
    import fl.controls.UIScrollBar;
        
    import flash.display.Sprite;
        
    import flash.events.Event;
        
    import flash.net.URLLoader;
        
    import flash.net.URLLoaderDataFormat;
        
    import flash.net.URLRequest;
        
    import flash.text.TextField;
        
        public class 
    DocumentClass extends Sprite
        
    {
            private var 
    my_sb:UIScrollBar;
            private var 
    my_loader:URLLoader;
            
            public function 
    DocumentClass():void
            
    {
                
    my_loader = new URLLoader();
                
    my_sb = new UIScrollBar();
                
                
    my_loader.addEventListener(Event.COMPLETEonHTMLloaded);
                
    my_loader.dataFormat URLLoaderDataFormat.VARIABLES;
                
    my_loader.load(new URLRequest("index.html"));
            }
            
            private function 
    onHTMLloaded(e:Event):void 
            
    {
                
    my_txt.text e.target.data.content;
                
    my_title.text e.target.data.title;
                
                
    my_sb.scrollTarget my_txt;
                
    my_sb.setSize(16my_txt.height);
                
    my_sb.move(my_txt.my_txt.width 5my_txt.y);
                
    my_sb.update();
            }
        }

    Put this in a file with your swf called "DocumentClass.as" and enter the document class on your properties dialog as "DocumentClass".

  5. #5
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    I got this output error when I ran it.

    PHP Code:
    ErrorError #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
        
    at Error$/throwError()
        
    at flash.net::URLVariables/decode()
        
    at flash.net::URLVariables$iinit()
        
    at flash.net::URLLoader/flash.net:URLLoader::onComplete() 

  6. #6

  7. #7
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    PHP Code:
    &title=Latest News
    &content
    <
    img src="photo_gallery1.jpg" width="61" height="64" align="left"><a href="http://www.entheosweb.com/Flash/free_flash_photo_gallery.asp" class="heading">Free  Flash and XML Photo Galleries</a></p>
    <
    p>Download any of the Entheos free Dynamic Flash Photo Galleries todayYou don't need the Flash software for editing the gallery. You can easily add, edit or delete pictures by editing the xml file in Notepad. All images are loaded externally. Add unlimited number of images!</p> 
    <img src="games.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/flash_games/index.asp" class="heading">Free Flash  Games</a>
    Free educational Flash games for kids including coloring, drawing, puzzles, memory game, join the dots, shooting and more.<br/>
    <img src="background.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/fireworks/background1.asp" class="heading">Free Website Backgrounds</a>
    Download these attractive free website background images for your website. 

  8. #8
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Should be:
    PHP Code:
    title=Latest News 
    &content
    <
    img src="photo_gallery1.jpg" width="61" height="64" align="left"><a href="http://www.entheosweb.com/Flash/free_flash_photo_gallery.asp" class="heading">Free  Flash and XML Photo Galleries</a></p
    <
    p>Download any of the Entheos free Dynamic Flash Photo Galleries todayYou don't need the Flash software for editing the gallery. You can easily add, edit or delete pictures by editing the xml file in Notepad. All images are loaded externally. Add unlimited number of images!</p>
    <img src="games.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/flash_games/index.asp" class="heading">Free Flash  Games</a> 
    Free educational Flash games for kids including coloring, drawing, puzzles, memory game, join the dots, shooting and more.<br/> 
    <img src="background.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/fireworks/background1.asp" class="heading">Free Website Backgrounds</a> 
    Download these attractive free website background images for your website. 

  9. #9
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    I am not sure what I am doing wrong man, here is a zip file that contains all of my old and new work. The ~news was the old one. NEWS FILES

  10. #10
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Sorry, missed the most important part:

    my_txt.htmlText = e.target.data.content;
    my_title.htmlText = e.target.data.title;

  11. #11
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    Thank you so much it works great. Whe I add it into my main document I get a bunch of 1046 errors for every button I have on the timeline. I'm going to look it up but I may be back with another question for you.

    Thanks again!

  12. #12
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    Ok it is because this function, does it make sense to you?
    PHP Code:
    function buttonNavClick1(event:MouseEvent):void{
    gotoAndStop("registry");
    }; 

  13. #13
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    So I was thinking about it and I moved all of my AS from my main file into the DocumentClass.as file. There are no more errors but my btns do not work. Here is the code do you know why they will not work?

    PHP Code:
    // News Application
    package {
        
    import fl.controls.UIScrollBar;
        
    import flash.display.Sprite;
        
    import flash.events.Event;
        
    import flash.net.URLLoader;
        
    import flash.net.URLLoaderDataFormat;
        
    import flash.net.URLRequest;
        
    import flash.text.TextField;
        
        public class 
    DocumentClass extends Sprite
        
    {
            private var 
    my_sb:UIScrollBar;
            private var 
    my_loader:URLLoader;
            
            public function 
    DocumentClass():void
            
    {
                
    my_loader = new URLLoader();
                
    my_sb = new UIScrollBar();
                
                
    my_loader.addEventListener(Event.COMPLETEonHTMLloaded);
                
    my_loader.dataFormat URLLoaderDataFormat.VARIABLES;
                
    my_loader.load(new URLRequest("content.html"));
            }
            
            private function 
    onHTMLloaded(e:Event):void 
            
    {
                
    my_txt.htmlText e.target.data.content;
                
    my_title.htmlText e.target.data.title;
                
    my_sb.scrollTarget my_txt;
                
    my_sb.setSize(16my_txt.height);
                
    my_sb.move(my_txt.my_txt.width 5my_txt.y);
                
    my_sb.update();
            }
        }



    // Main Navigation
    btn_registry.addEventListener(MouseEvent.CLICKbuttonNavClick1);

    function 
    buttonNavClick1(event:MouseEvent):void{
    gotoAndStop("registry");
    };

    btn_inursery.addEventListener(MouseEvent.CLICKbuttonNavClick2);

    function 
    buttonNavClick2(event:MouseEvent):void{
    gotoAndStop("inursery");
    };

    btn_sales.addEventListener(MouseEvent.CLICKbuttonNavClick3);

    function 
    buttonNavClick3(event:MouseEvent):void{
    gotoAndStop("sales");
    };

    btn_news.addEventListener(MouseEvent.CLICKbuttonNavClick4);

    function 
    buttonNavClick4(event:MouseEvent):void{
    gotoAndStop("news");
    };


    // Timer Movie Clips
    if (currentLabel == "registry") { 
        
    mc_1.gotoAndPlay (1); 


    if (
    currentLabel == "inursery") { 
        
    mc_2.gotoAndPlay (41); 


    if (
    currentLabel == "sales") { 
        
    mc_3.gotoAndPlay (83); 


    if (
    currentLabel == "news") { 
        
    mc_4.gotoAndPlay (124); 



    //Timer Buttons
    btn_1.addEventListener(MouseEvent.CLICKclearBtn1);

    function 
    clearBtn1(event:MouseEvent):void{
    gotoAndStop("registry");
    };

    btn_2.addEventListener(MouseEvent.CLICKclearBtn2);

    function 
    clearBtn2(event:MouseEvent):void{
    gotoAndStop("inursery");
    };

    btn_3.addEventListener(MouseEvent.CLICKclearBtn3);

    function 
    clearBtn3(event:MouseEvent):void{
    gotoAndStop("sales");
    };

    btn_4.addEventListener(MouseEvent.CLICKclearBtn4);

    function 
    clearBtn4(event:MouseEvent):void{
    gotoAndStop("news");
    }; 

  14. #14
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Your listeners and functions need to be inside the class, you have them all outside the class currently.

    PHP Code:
    public function DocumentClass():void 
            

                
    my_loader = new URLLoader(); 
                
    my_sb = new UIScrollBar(); 
                 
                
    my_loader.addEventListener(Event.COMPLETEonHTMLloaded); 
                
    my_loader.dataFormat URLLoaderDataFormat.VARIABLES
                
    my_loader.load(new URLRequest("content.html")); 
    btn_registry.addEventListener(MouseEvent.CLICKbuttonNavClick1); 
            } 

    private function 
    buttonNavClick1(event:MouseEvent):void
    gotoAndStop("registry"); 
    }; 

  15. #15
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    When I put them inside the class the script is fine. But when I test it I compile errors on every
    PHP Code:
    private function buttonNavClick1(event:MouseEvent):void
    line. It is a 1046: Type was not found or was not compile-time constant: MouseEvent.

  16. #16

  17. #17
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    I am not sure why I can not get this to work. Can you take a look at my files and tell me what I am doing wrong? Thank you TEST FILES

  18. #18

  19. #19
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    When you get a chance check out the fla. when you test it the animation dosen't play and the main nav btns dont work all the time.

  20. #20

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