Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-24-2007, 11:08 PM   #1
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default AS 2.0 & AS 3.0: Same project - best practice

Attached is the same project as an AS Flash 8 and as Flash 9 (AS 2.0 / AS 3.0).

Could I please get some feedback from you guys as to the very best OO practice for making this simple little application.

Thanks



FLASH VERSION 8
fla:
ActionScript Code:
stop(); import com.flash8.xml.*; import com.flash8.loaders.*; // load xml var images:ImagesXML = new ImagesXML(); images.addEventListener(ImagesXML.LOAD, onLoadXML); images.load("images.xml"); // init loading of images var loader1:LoadImage = new LoadImage(pic1); loader1.addEventListener(LoadImage.LOAD, onLoadImage); var loader2:LoadImage = new LoadImage(pic2); loader2.addEventListener(LoadImage.LOAD, onLoadImage); var loader3:LoadImage = new LoadImage(pic3); loader3.addEventListener(LoadImage.LOAD, onLoadImage); function onLoadXML():Void {     loader1.load(images._images[0][0]);     loader2.load(images._images[0][1]);     loader3.load(images._images[0][2]); } function onLoadImage(dispatch):Void {     dispatch.target._xscale = dispatch.target._yscale = 30;     dispatch.target.onPress = startDrag;     dispatch.target.onRelease = stopDrag; }

classes
ActionScript Code:
import mx.utils.Delegate; import mx.events.EventDispatcher; class com.flash8.xml.ImagesXML {     private var xml:XML;     private var images:Array;     private var urls:Array;     private var ids:Array;             public static var LOAD:String = "load";         // shut up compiler     public var addEventListener:Function;     public var dispatchEvent:Function;         public function ImagesXML()     {         xml = new XML();         xml.ignoreWhite = true;         xml.onLoad = Delegate.create(this, onLoad);                 images = new Array();         urls   = new Array();         ids    = new Array();                 EventDispatcher.initialize(this);     }         public function load(file:String):Void     {         xml.load(file);     }         private function onLoad(success:Boolean):Void     {         var nodes:Array = xml.firstChild.childNodes;                 for (var i:Number=0; i<nodes.length; i++)         {             urls[i] = nodes[i].firstChild.nodeValue;             ids[i]    = nodes[i].attributes.id         }                 images.push(urls);         images.push(ids);                 dispatchEvent( {type:LOAD, target:this} );     }             public function get _images():Array { return images; } }
ActionScript Code:
import mx.utils.Delegate; import mx.events.EventDispatcher; class com.flash8.loaders.LoadImage {     private var target:MovieClip;     private var mcl:MovieClipLoader;         public static var LOAD:String = "load";         // shut up compiler     public var addEventListener:Function;     public var dispatchEvent:Function;             public function LoadImage(target:MovieClip)     {         this.target = target;         mcl = new MovieClipLoader();         mcl.addListener(this);                 EventDispatcher.initialize(this);             }         public function load(url:String):Void     {         mcl.loadClip(url, target);     }         private function onLoadProgress(target:MovieClip, loaded:Number, total:Number):Void     {         //trace("loading");     }         private function onLoadInit(target:MovieClip):Void     {         dispatchEvent( {type:LOAD, target:target, scope:this} );     } }

FLASH VERSION 9
fla:
ActionScript Code:
stop(); import com.flash9.xml.*; import com.flash9.loaders.*; // load xml var images:ImagesXML = new ImagesXML(); images.addEventListener(ImagesXML.LOAD, onLoadXML); images.load("images.xml"); // init loading of images var loader1:LoadImage = new LoadImage(pic1); loader1.addEventListener(LoadImage.LOAD, onLoadImage); var loader2:LoadImage = new LoadImage(pic2); loader2.addEventListener(LoadImage.LOAD, onLoadImage); var loader3:LoadImage = new LoadImage(pic3); loader3.addEventListener(LoadImage.LOAD, onLoadImage); function onLoadXML(event:Event):void {     loader1.load( images.xml.url[0]);     loader2.load(images.xml.url[1]);     loader3.load(images.xml.url[2]); }

classes:
ActionScript Code:
package com.flash9.xml {         import flash.net.URLLoader;     import flash.net.URLLoaderDataFormat;     import flash.net.URLRequest;     import flash.events.Event;     import flash.events.EventDispatcher;         public class ImagesXML extends EventDispatcher     {                 protected var loader:URLLoader;                 public static const LOAD:String = "load";                 public function ImagesXML()         {             loader = new URLLoader();             loader.dataFormat = URLLoaderDataFormat.TEXT;             loader.addEventListener(Event.COMPLETE, onComplete);         }                 public function load(file:String):void         {             loader.load( new URLRequest(file) );         }                 protected function onComplete(event:Event):void         {             dispatchEvent( new Event(LOAD) );         }                         public function get xml():XML { return new XML(loader.data); }     } }
ActionScript Code:
package com.flash9.loaders {     import flash.display.Loader;     import flash.net.URLRequest;     import flash.events.Event;     import flash.display.Sprite;     import flash.events.MouseEvent;         public class LoadImage extends Sprite     {         protected var loader:Loader;         protected var target:*;   // what is the datatype for a movieclip on the stage?                 public static const LOAD:String = "LOAD";                         public function LoadImage(_target:*)         {             target = _target;             target.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);             target.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);                         loader = new Loader();             addChild(loader);             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadInit);                     }                 public function load(url:String):void         {             loader.load( new URLRequest(url) );         }                         protected function onLoadInit(event:Event):void         {             this.scaleX = this.scaleY = .30;             target.addChild(this);             dispatchEvent( new Event(LOAD) );         }                 protected function onMouseUp(event:MouseEvent):void         {             target.stopDrag();         }                 protected function onMouseDown(event:MouseEvent):void         {             target.startDrag();         }                 } }

XML FILE TO LOAD
HTML Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<images>
	<url id="1">http://images.askmen.com/galleries/actress/courtney-cox/pictures/courtney-cox-picture-1.jpg</url>
	<url id="3">http://spoilerbuzz.com/wp-content/uploads/2006/12/courtneycox.jpg</url>
	<url id="2">http://i26.photobucket.com/albums/c139/denee34/courteney-cox-1280x960-16546.jpg</url>
</images>
Attached Files
File Type: zip xml and images.zip (18.6 KB, 198 views)
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 06-25-2007, 02:00 PM   #2
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

the type is sprite or movieclip depending on what it is.
never put code on a timeline, that is a bad practise. flash 9 you can assign a class to your stage, a much better approach.
why do you create your loaders immediatly. if your xml changes you are fooked. wait till your xml loads and then loop through it and create what you need.
personally i do not even think you need the loadimage class.

you realise with your images you will need a server(s) policy file(s)
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 07-02-2007, 06:36 AM   #3
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

thanks hangalot!


I made a new one, but I still have code on the timeline
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can anyone convert this Actionscript 2.0 code to Actionscript 3.0 code ? ih32page ActionScript 3.0 3 08-20-2007 01:44 AM
Importing flex project into flash project in flex builder 2 devboy Flex 2 & 3 1 05-14-2007 11:28 AM
How to convert AS 2.0 code to AS 3.0 mohitjaitly ActionScript 3.0 7 05-04-2007 10:20 AM
Loading AS 3.0 movie from AS 2.0 leogesteira ActionScript 3.0 1 03-15-2007 03:53 PM
Project Fallen Heroes jor133d General Chat 1 08-22-2006 03:10 AM


All times are GMT. The time now is 05:03 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.