Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 3 of 3

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

  1. #1
    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.

    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;
    		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);
    			} 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.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 {
    					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
    			_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 {
    			var intervalId:uint = setTimeout(fadeOut,_duration*1000);
    	} // 	/class
    } // 	/package

  2. #2
    try Event.INIT instead

  3. #3
    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


Copyright 1999 - 2012