how to unload externally loaded swf which contains 3D Carousel?


hello all

 

i learning as3 , have been taking on various tutorials found on net. while learning as3 came across lesson on http://tutorials.flashmymind.com/2009/05/vertical-3d-carousel-with-actionscript-3-and-xml/ titled "vertical 3d carousel as3 , xml".

 

i completed tutorial , worked fine wanted load swf existing project. loading of swf goes fine , when unload loader removed visually in output panel in flash cs5 error follows

 

typeerror: error #1009: cannot access property or method of null object reference.
at carousel_c_fla::maintimeline/movecarousel()

 

this error repeats on , on again slowing swf movie.

 

so mean main flash movie trying still play / find unloaded 3d carousel?

 

if how unload remove as3 trying run 3d carousel?

 

i have included as3 below tutorial page , understand have remove "break free" 3d carousel swf when unloaded. stuck knowledge of as3 limited - can guys / girls help?

 

//import tweenmax import com.greensock.*;  //the path xml file (use own here) // old var tutorial - var xmlpath:string = "http://tutorials.flashmymind.com/xml/carousel-menu.xml"; var xmlpath:string = "carousel-menu.xml"; //we'll store loaded xml variable var xml:xml;  //create loader , load xml. call function "xmlloaded" when done. var loader = new urlloader(); loader.load(new urlrequest(xmlpath)); loader.addeventlistener(event.complete, xmlloaded);  //this function called when xml file loaded function xmlloaded(e:event):void {       //make sure not working null variable      if ((e.target urlloader) != null ) {            //create new xml object loaded xml data           xml = new xml(loader.data);            //call function creates menu           createmenu();      } }  //we need know how many items have on stage var numberofitems:uint = 0;  //this array contain menu items var menuitems:array = new array();  //set focal length var focallength:number = 350;  //set vanishing point var vanishingpointx:number = stage.stagewidth / 2; var vanishingpointy:number = stage.stageheight / 2;  //we calculate anglespeed in enter_frame listener var anglespeed:number = 0;  //radius of circle var radius:number = 128;  //this function creates menu function createmenu():void {       //get number of menu items have      numberofitems = xml.items.item.length();       //calculate angle difference between menu items (in radians)      var angledifference:number = math.pi * (360 / numberofitems) / 180;       //we use counter know how many menu items have been created      var count:uint = 0;       //loop through <button></button> nodes in xml      for each (var item:xml in xml.items.item) {            //create new menu item           var menuitem:menuitem = new menuitem();            //calculate starting angle menu item           var startingangle:number = angledifference * count;            //set "currentangle" attribute menu item           menuitem.currentangle = startingangle;            //position menu item           menuitem.xpos3d = 0;           menuitem.ypos3d = radius * math.sin(startingangle);           menuitem.zpos3d = radius * math.cos(startingangle);            //calculate scale ratio menu item (the further item -> smaller scale ratio)           var scaleratio = focallength/(focallength + menuitem.zpos3d);            //scale menu item according scale ratio           menuitem.scalex = menuitem.scaley = scaleratio;            //position menu item stage (from 3d 2d coordinates)           menuitem.x = vanishingpointx + menuitem.xpos3d * scaleratio;           menuitem.y = vanishingpointy + menuitem.ypos3d * scaleratio;            //add text menu item           menuitem.menutext.text = item.label;            //add "linkto" variable url           menuitem.linkto = item.linkto;            //we don't want text field catch mouse events           menuitem.mousechildren = false;            //assign mouse_over, mouse_out , click listeners menu item           menuitem.addeventlistener(mouseevent.mouse_over, mouseoveritem);           menuitem.addeventlistener(mouseevent.mouse_out, mouseoutitem);           menuitem.addeventlistener(mouseevent.click, itemclicked);            //add menu item menu items array           menuitems.push(menuitem);            //add menu item stage           addchild(menuitem);            //assign initial alpha           menuitem.alpha = 0.3;            //add blur item           tweenmax.to(menuitem,0, {blurfilter:{blurx:1, blury:1}});            //update count           count++;      } }  //add enter_frame listener animation addeventlistener(event.enter_frame, movecarousel);  //this function called in each frame function movecarousel(e:event):void {       //calculate angle speed according mousey position      anglespeed = (mousey - stage.stageheight / 2) * 0.0002;       //loop through menu items      for (var i:uint = 0; < menuitems.length; i++) {            //store menu item local variable           var menuitem:menuitem = menuitems[i] menuitem;            //update current angle of item           menuitem.currentangle += anglespeed;            //calculate scale ratio           var scaleratio = focallength/(focallength + menuitem.zpos3d);            //scale item according scale ratio           menuitem.scalex=menuitem.scaley=scaleratio;            //set new 3d coordinates           menuitem.xpos3d=0;           menuitem.ypos3d=radius*math.sin(menuitem.currentangle);           menuitem.zpos3d=radius*math.cos(menuitem.currentangle);            //update item's coordinates.           menuitem.x=vanishingpointx+menuitem.xpos3d*scaleratio;           menuitem.y=vanishingpointy+menuitem.ypos3d*scaleratio;       }       //call function sorts items overlap each other correctly      sortz(); }  //this function sorts items overlap each other correctly function sortz():void {       //sort array item has highest       //z position (= furthest away) first in array      menuitems.sorton("zpos3d", array.numeric | array.descending);       //set new child indexes item      for (var i:uint = 0; < menuitems.length; i++) {           setchildindex(menuitems[i], i);      } }  //this function called when mouse on item function mouseoveritem(e:event):void {       //tween item's properties      tweenmax.to(e.target, 0.1, {alpha: 1, glowfilter:{color:0xffffff, alpha:1, blurx:60, blury:60},blurfilter:{blurx:0, blury:0}}); }  //this function called when mouse out of item function mouseoutitem(e:event):void {       //tween item's properties      tweenmax.to(e.target, 1, {alpha: 0.3, glowfilter:{color:0xffffff, alpha:1, blurx:0, blury:0},blurfilter:{blurx:1, blury:1}}); }  //this function called when item clicked function itemclicked(e:event):void {       //navigate url that's assigned menu item      var urlrequest:urlrequest=new urlrequest(e.target.linkto);      navigatetourl(urlrequest);  } 

 

 

 

 


if code within file load, less code need attend to.  need unload loader , null out references loaded content.  if show code main file involving loading , unloading of carousel may better able help.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

How to decompile jsxbin to jsx

Gavik Photoslide GK2: Not able to upload photos - Joomla! Forum - community, help and support

Phoca Guestbook logger registret bruger af - Joomla! Forum - community, help and support