Results 1 to 3 of 3

Thread: loading external SWF or IMG, why is width and height 0?

  1. #1
    23
    posts
    Registered User

    loading external SWF or IMG, why is width and height 0?

    I am making a slideshow and have an custom class "slide", which extends Sprite. The slides are loaded and then fade in and out.

    In my main FLA file I load an XML file with slides, that contain either text, an image or an SWF clip. When I load an image or a SWF, my slide always have widths and heights of 0. I don't understand that.

    It's a larger problem for the SWF (which doesn't center, although the images mysteriously center).

    Additionally, the SWF starts playing immediately and I cannot figure out how to stop it and call it only when I want it and to keep it from looping!

    Can someone please help me? Thanks.

    Code:
    package {
    	
    	import flash.display.Sprite;
    	import flash.display.*; 
    	import flash.text.*; 
    	import flash.utils.*;
    	import fl.transitions.Tween;
    	import fl.transitions.TweenEvent;
    	import fl.transitions.easing.*;
    	
    	public class Slide extends Sprite {
    		
    		public var _content;
    		public var _type;
    		public var _imgDir = "images/";
    		public var _duration;
    		
    		private var _fadeIn:Tween;
    		private var _fadeOut:Tween;
    		
    		//consructor
    		public function Slide(i:int, txt:String, type:String, time:int) {
    			
    			this.name = i.toString(); // slide names are numbers 
    			_content = txt;
    			_type = type;
    			_duration = time;
    			
    	
    			if (_type=="text") {
    				
    				var myFont:Font = new Perpetua(); //from library
    				
    				var txtFmt:TextFormat = new TextFormat();
    				
    				txtFmt.font = myFont.fontName;
    				txtFmt.color = 0xffffff;
    				txtFmt.size = 32;
    				txtFmt.leading = 4;
    				txtFmt.align = "center";
    				
    				
    				var txtFld:TextField = new TextField();
    				txtFld.defaultTextFormat = txtFmt;
    				txtFld.x = txtFld.y = 0;
    				txtFld.width = 650;
    				txtFld.selectable = false;
    				txtFld.border = false;
    				txtFld.embedFonts = true;
    				txtFld.antiAliasType = AntiAliasType.ADVANCED;
    				txtFld.background = false;
    				txtFld.multiline = true;
    				txtFld.wordWrap = true;
    				txtFld.autoSize = TextFieldAutoSize.LEFT;
    				
    				
    				txtFld.htmlText = _content;
    				
    				//center textfield within Slide object
    				txtFld.x = (720/2)-(txtFld.width/2);
    				txtFld.y = (405/2)-(txtFld.height/2);
    				
    				addChild(txtFld);
    								
    				
    			} else if (_type == "img") {
    				//load image
    				var ldr:Loader = new Loader();
    				ldr.load(new URLRequest(_imgDir + _content));
    				ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
    				
    				//image is loaded
    				function loaded(evt:Event):void {
    					var img:Sprite = new Sprite();
    					img.addChild(evt.target.content);
    					addChild(img);
    					
    					img.width = evt.target.content.width;
    					img.height = evt.target.content.height;
    					img.scaleX = .8;
    					img.scaleY = .8;
    
    					img.x = (720/2)-(img.width/2);
    					img.y = (405/2)-(img.height/2);
    										
    					//trace("img.width: " + img.width + " img.height: " + img.height);
    					//trace("img.x: " + img.x + " img.y: " + img.y);
    					
    				}
    				
    			} else if (_type=="swf") {
    				//load swf
    				var ldr:Loader = new Loader();
    				ldr.load(new URLRequest(_imgDir + _content));
    				ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfloaded);
    			
    				function swfloaded(evt:Event):void {
    					
    					addChild(evt.target.content);
    					evt.target.content.x = (720/2)-(evt.target.content.width/2);
    					evt.target.content.y = (405/2)-(evt.target.content.height/2);
    					
    					evt.target.content.stop(); //stops it.
    					
    					
    				}
    				
    			}
    
    			this.alpha = 0; //default, hidden
    		
    		}
    		
    		
    	
    		public function fadeIn():void {
    			//if(_type=="swf")	// does not work
    				//this.play();
    			_fadeIn = new Tween(this, "alpha", Regular.easeOut, this.alpha, 1, 2, true);
    		}
    		
    		public function fadeOut():void {
    			_fadeOut = new Tween(this, "alpha", Regular.easeOut, this.alpha, 0, 3, true);
    		}
    
    		public function appear():void {
    			this.fadeIn();
    			var intervalId:uint = setTimeout(fadeOut,_duration*1000);
    		}
    		
    		
    		
    		
    	} // 	/class
    	
    } // 	/package

  2. #2
    try Event.INIT instead

  3. #3
    23
    posts
    Registered User
    Nope, it still doesn't work....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012