Hi Cor, I meant to say that the movie I was loading in is an as2 swf.
the container is as3. Kurt -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Cor Sent: Wednesday, June 17, 2009 9:25 AM To: 'Flash Coders List' Subject: RE: [Flashcoders] understand getChildByName This all looks AS3 to me. Did I misunderstood AS2? -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Kurt Dommermuth Sent: woensdag 17 juni 2009 15:13 To: 'Flash Coders List' Subject: RE: [Flashcoders] understand getChildByName Hi Cor, Thank you for reading this Cor. It is a package and it looks like below. It is one of my first attempts so if you see any other room for improvement it would be welcome. ____________________________________ The call to the loader looks like this: var mc:MovieClip = new MovieClip(); var m = main.addChild(mc); mc.name = "btn_nav" var callback:Object = new Object(); callback.fn = initGameNav; callback.mc = m; var l:Assetloader = new Assetloader(mc, "game_buttons_as3.swf", callback); ____________________________________ package com.dom.Loaders { import flash.display.Stage; import flash.display.MovieClip; import flash.display.Loader; import flash.display.LoaderInfo; import flash.events.*; import flash.net.URLRequest; import flash.net.URLLoader; import flash.text.TextField; import com.dom.Utilities.FeedbackMessage; import flash.utils.getDefinitionByName; public class Assetloader extends MovieClip { private var _path:MovieClip; private var _url:String; private var _callback:Object; private var _p:preloaderMC; private var _loader:Loader; private var _error:FeedbackMessage; public function Assetloader(path:MovieClip, url:String, callback:Object=null):void { _path = path; _url = url; _callback = callback; initLoader(); } private function initLoader():void { var request:URLRequest = new URLRequest(_url); _loader = new Loader(); _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleError); _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress); _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); _loader.load(request); //initiate loading of main.swf trace("_callback.mc = " + _callback.mc) _path.addChild(_loader); trace("_callback.mc2 = " + _callback.mc) } // Update the percentage display private function loadProgress(event:ProgressEvent):void { var percentLoaded:Number = event.bytesLoaded / event.bytesTotal; percentLoaded = Math.round(percentLoaded * 100); } //remove the loader and free up resources private function cleanUp():void { _loader.removeEventListener(IOErrorEvent.IO_ERROR, handleError); _loader.removeEventListener(ProgressEvent.PROGRESS, loadProgress); _loader.removeEventListener(Event.COMPLETE, loadComplete); if(_p!=null) { _p.parent.removeChild(_p); } _p = null; } // Load complete, hide the animating graphic and text private function loadComplete(event:Event):void { _callback.load_info = new Object() _callback.load_info = event.target; _callback.mc = event.target.content; _callback.fn(_callback); cleanUp(); } private function handleError(e:IOErrorEvent):void { trace("Error loading File"); var msg:String = "The file '" + _url + "' could not be loaded." _error = new FeedbackMessage(msg,_callback.path); cleanUp() } } } _________________________________ The Return or on complete function essentially looks like this: function initGameNav(o:Object):void { var game_button_ar:Array = o.mc.games; var game_ar_len:Number = game_button_ar.length; for(var i:Number=1;i<=game_ar_len;i++) { var newY:Number; var asset_name:String = game_button_ar[(i-1)][0]; var asset_game_to_load:String = game_button_ar[(i-1)][1]; var asset_class = o.load_info.applicationDomain.getDefinition(asset_name) as Class; var asset_mc:MovieClip = new asset_class() as MovieClip; o.mc.addChild(asset_mc); //trace("game to load = " + asset_game_to_load) asset_mc.asset_game_to_load = asset_game_to_load; asset_mc.scaleX = .50 asset_mc.scaleY = .50 if(i<=10) { newY = 0 asset_mc.x = ((i-1) * asset_mc.bg.width/2) + asset_mc.bg.width/2 } else { newY = 80; asset_mc.x = ((i-11) * asset_mc.bg.width/2) + asset_mc.bg.width/2 } asset_mc.y = newY; .....................etc... _____________________________________ Kurt -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Cor Sent: Wednesday, June 17, 2009 8:34 AM To: 'Flash Coders List' Subject: RE: [Flashcoders] understand getChildByName Hi Kurt, How do you load youe swf into your myMC? -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Kurt Dommermuth Sent: woensdag 17 juni 2009 13:57 To: 'Flash Coders List' Subject: [Flashcoders] understand getChildByName Hi All, New to AS3. I'm sure I must be missing something obvious, but I'm at a loss. Example: I have created a movie clip - called "myMC". I added it to an existing movie clip called "main" (main.addChild(myMC)). At this point myMC traces as [object MovieClip]. I load an as2 swf into myMC. At this point myMC traces as [object MainTimeline]. I change myMC's y value to 100 and it traces as 100. Later I want to move it again. To reference it I create a variable like this: var mc:DisplayObject = main.getChildByName("myMC"); Now when I trace mc's y value it is 0. I don't know why. Does the trace [object MainTimeline] indicate that I've used addChild incorrectly? Should I have added myMC to "main" after it had loaded? Why did it go from a MovieClip object to a MainTimeline object? Does the fact that I'm loading in an as2 swf have anything to do with it? Any help would be appreciated. Thank you, Kurt _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

