AS3 Class... what's wrong with it

  • minimingus
  • Newbie
  • Newbie
  • minimingus
  • Posts: 5

Post 3+ Months Ago

Code: [ Select ]
 
Main.as
var images:Array = new Array("image1.jpg". "image2.jpg", "image3.jpg");
 
for each(var index in images){
  var imageObjects:Image = new Image(index);
}
 
#############################
Image.as
 
package {
   
    import flash.display.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import ImageInteraction;
   
   
    public class Image extends Sprite{
       
        private var image:String;
        private var imageArray:Array;
        private var init_x:Number = 100;
        private var init_y:Number = 100;
        private var spacing:Number = 240;
        private var holder:Sprite = new Sprite();
        //private var _loader:Loader = new Loader();
        //private var url_request:URLRequest = new URLRequest();
       
       
    public function Image(image:String){
     var interact:ImageInteraction = new ImageInteraction();
        loadImage(image);
        }
       
    private function loadImage(image){
   
     var _loader:Loader = new Loader();
     var url_request:URLRequest = new URLRequest(image);
     addChild(holder);
    _loader.load(url_request);
    _loader.x = init_x;
    _loader.y = init_y;
    holder.addChild(_loader);
 
    }
 
  1.  
  2. Main.as
  3. var images:Array = new Array("image1.jpg". "image2.jpg", "image3.jpg");
  4.  
  5. for each(var index in images){
  6.   var imageObjects:Image = new Image(index);
  7. }
  8.  
  9. #############################
  10. Image.as
  11.  
  12. package {
  13.    
  14.     import flash.display.*;
  15.     import flash.net.URLLoader;
  16.     import flash.net.URLRequest;
  17.     import flash.display.Sprite;
  18.     import flash.events.MouseEvent;
  19.     import ImageInteraction;
  20.    
  21.    
  22.     public class Image extends Sprite{
  23.        
  24.         private var image:String;
  25.         private var imageArray:Array;
  26.         private var init_x:Number = 100;
  27.         private var init_y:Number = 100;
  28.         private var spacing:Number = 240;
  29.         private var holder:Sprite = new Sprite();
  30.         //private var _loader:Loader = new Loader();
  31.         //private var url_request:URLRequest = new URLRequest();
  32.        
  33.        
  34.     public function Image(image:String){
  35.      var interact:ImageInteraction = new ImageInteraction();
  36.         loadImage(image);
  37.         }
  38.        
  39.     private function loadImage(image){
  40.    
  41.      var _loader:Loader = new Loader();
  42.      var url_request:URLRequest = new URLRequest(image);
  43.      addChild(holder);
  44.     _loader.load(url_request);
  45.     _loader.x = init_x;
  46.     _loader.y = init_y;
  47.     holder.addChild(_loader);
  48.  
  49.     }
  50.  


Can anyone explain why everthing loads but the image does not appear on the stage?

Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

You have a period after "image1.jpg" instead of a comma in your array?

var images:Array = new Array("image1.jpg". "image2.jpg", "image3.jpg");
  • minimingus
  • Newbie
  • Newbie
  • minimingus
  • Posts: 5

Post 3+ Months Ago

Thanks for the reply, but with change the images are still not being displayed on the stage. This has to be something simple, but I haven't been able to locate the fault. I have looked at it too long.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I'm still a novice with packages and classes and was always pretty horrible when it comes to arrays, but have you tried a trace on image to see what is returned?

I guess I'm having a hard time seeing where you are putting the image urls in the array into the image variable that you are trying to load. (It's probably because I'm a noob and suck at arrays anyway)

Normally without an array your URLRequest would like more like this
Code: [ Select ]
var url:String = "http://www.[yourDomain].com/image1.jpg";
            var request:URLRequest = new URLRequest(url);
 
  1. var url:String = "http://www.[yourDomain].com/image1.jpg";
  2.             var request:URLRequest = new URLRequest(url);
  3.  

http://livedocs.adobe.com/flex/2/langre ... quest.html
  • minimingus
  • Newbie
  • Newbie
  • minimingus
  • Posts: 5

Post 3+ Months Ago

The child has to be loaded in the main file (Main.as).

# Main.as
# var images:Array = new Array("image1.jpg". "image2.jpg", "image3.jpg");
#
# for each(var index in images){
# var imageObjects:Image = new Image(index);
# addChild(imageObjects);
# }

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.