A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: WTB Flash Guru

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    128

    WTB Flash Guru

    Code:
    for(var i = 0; i < m_nSize; i++)
    {
       //trace(xml.ImageSet[i].@src);
       sImageSet = xml.ImageSet[i].@src;
       var m:cMovie = new cMovie(sImageSet);
       m_aMovieSets.push(m);
    }
    Im trying to put a cMovie, a class that I have created, into my array. Only problem is once I do the listener never gets called in order to read in an xml file that I setup upon instantiation of the object. Also by doing it the way that I am am I creating a copy as its inserted into the array or is this a reference? Im still new to flash so bare with me. Thanks ahead of time.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    WTB? I don't think that's been legal for a few hundred years.

    The cMovie instance in the array is the same object as the one created a line above. That is, it is a reference, not a copy.

    You haven't posted any of your code dealing with listeners, so we can't determine what's wrong there.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Its legal according to congress, but then again what are they doing right these day lol.

    Code:
    package ActionScript
    {
    	//=======================================
    	// cMovie
    	//
    	// Purpose: Hold our movie info
    	//=======================================
    	import flash.net.URLLoader;
    	import flash.net.URLRequest;
    	import ActionScript.cMovie;
    	import flash.events.*;
    	
    	public class cMovie
    	{
    		// Member vars
    		private var m_sFile:String;
    		private var m_aImages:Array;
    		private var m_nSize:Number;
    		private var m_bLoaded:Boolean;
    		
    		//=======================================
    		// LoadImages
    		//
    		// In: e - The data we need.
    		//
    		// Purpose: Simple Constructor.
    		//=======================================
    		private function LoadImages(e:Event):void
    		{
    			var xml:XML = new XML(e.target.data);
    			m_nSize = xml.Images.length();
    			
    			for(var i = 0; i < m_nSize; i++)
    				m_aImages.push(xml.Images.Image[i]);
    				
    			m_bLoaded = true;
    		}
    		
    		//=======================================
    		// Constructor
    		//
    		// In: sFile - The file to load.
    		//
    		// Purpose: Simple Constructor.
    		//=======================================
    		public function cMovie(sFile:String = "")
    		{
    			m_bLoaded = false;
    			m_sFile = sFile;
    			Load();
    		}
    		
    		//=======================================
    		// Load
    		//
    		// Purpose: Loads our images.
    		//=======================================
    		public function Load():void
    		{
    			var xmlLoader:URLLoader = new URLLoader();
    			xmlLoader.addEventListener(Event.COMPLETE, LoadImages);
    			xmlLoader.load(new URLRequest(m_sFile));
    		}
    		
    		//=======================================
    		// Accessors/Mutators
    		//
    		// Purpose: Get and set our vars.
    		//=======================================
    		public function GetFile():String
    		{
    			return m_sFile;				
    		}
    		
    		public function GetImage(nIndex:Number = 0):String
    		{
    			return m_aImages[nIndex];
    		}	
    	}
    }
    This is my cMovie class I am doing the same thing in the class that that snipit came from, so Im not quit sure why it's not working. The only thing that I could think of would be that the array is not taking a reference so once scope ends the real cMovie gets garbage collected. But that can't be the case from what you say.

    Also there may be some stuff wrong in the latter but I'm not worried about that as of yet just trying to get past this crash point lol.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Stupid question time: how do you know the listener isn't being called?

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    I put a break point and it never gets to it. In my cLibrary class the one that is creating the instantiations I have a listener in there as well and the break point succeeds.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I'm not sure how whatever you're using handles breakpoints, but I don't see any reason cMovie wouldn't call the complete listener. Unless of course the load never completes, for example if the src attribute does not describe a valid file.

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    hmm Ill take a look at that I'm sure its something stupid like that lol. I was pretty sure that it passed the entire Load() but I could be wrong.

  8. #8
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Well I traced it I and it makes it all the way through the Load() all the files seem a go from the xml stand point. No clue what I could be doing though.

  9. #9
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Its seems to die right as I push it into the array. Do you have to specify something to push a certain type to be added to an array.

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Nope. Arrays are untyped. Vectors are typed.

    You do realize it's going to take some time to load all those files, right? You're not expecting immediate execution of the listeners, I hope. How many files are you trying to load? Perhaps you should reduce it to 1 or 2 just for testing.

  11. #11
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Yeah I know they take a bit, im only creating 1 cMovie right now cause I kenw it would take some time. I also have waited for a few mins to see if it would hit but nothing.

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    All I can think of is to add listeners for all the other events that may be happening instead. See the livedocs for URLLoader for examples.

  13. #13
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Do you know if I have to let the listener trigger before I am able to push it in the array?

  14. #14
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    ahhh, never mind lol, like I was saying it was going to be something stupid. I forgot to call new on my array so once I called push it just dumped out. Thanks for the help though.

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