I really need some help from you guys
I have created 2 sprites each containing a dynamic text field child. I then add this as a child of the stage. (I have done this in order to make the text clickable with a hand cursor on mouseover)
It loads in fine, I just run into problems when trying to REMOVE it the sprite containing the text.
“ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.”
Any hints from you guys out there?
[COLOR=Red]Sections concerned in red[/COLOR]:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import com.greensock.*;
import com.greensock.easing.*;
var columns:Number;
var my_x:Number;
var my_y:Number;
var my_thumb_width:Number;
var my_thumb_height:Number;
var my_images:XMLList;
var my_total:Number;
var myFont:Font = new helvetica();
var container_mc:MovieClip;
var full_mc:MovieClip;
var full_caption:TextField = new TextField();
var full_description:TextField = new TextField();
var full_price:TextField = new TextField();
var medium_price:TextField = new TextField();
var thumb_caption:TextField = new TextField();
[COLOR=Magenta]
//Items concerned are declared here.[/COLOR]
[COLOR=Red]var colour_opt1:TextField = new TextField();
var colour_opt2:TextField = new TextField();
var colour_opt1sprite:Sprite = new Sprite();
var colour_opt2sprite:Sprite = new Sprite();[/COLOR]
var mySpinBtn:spinbtn_mc = new spinbtn_mc();
var myCloseBtn:closebtn_mc = new closebtn_mc();
var myBuyBtn:buybtn_mc = new buybtn_mc();
var spin_url:String;
var shop_url:String;
var fullImage:Loader;
var x_counter:Number=0;
var y_counter:Number=0;
var my_tweens:Array=[];
var container_mc_tween:Tween;
var full_tween:Tween;
var tweento360:Tween;
var contact_tween:Tween;
var thumb_caption_tween:Tween;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("gallery.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
store_btn.addEventListener(MouseEvent.CLICK, gotostore);
function gotostore(e:MouseEvent):void {
navigateToURL(new URLRequest("http://s328432197.e-shop.info"));
}
contact_btn.addEventListener(MouseEvent.CLICK, gotocontact);
function gotocontact(event:MouseEvent):void {
contact_mc.gotoAndPlay(2);
contact_mc.alpha=.9;
if (container_mc) {
setChildIndex(container_mc, 0);
}
if (full_mc) {
setChildIndex(full_mc, 0.1);
setChildIndex(container_mc, 0);
TweenLite.to(full_description, 0.2, {alpha:0});
TweenLite.to(full_caption, 0.2, {alpha:0});
TweenLite.to(full_price, 0.2, {alpha:0});
TweenLite.to(medium_price, 0.2, {alpha:0});
TweenLite.to(colour_opt1sprite, 0.2, {alpha:0});
TweenLite.to(colour_opt2sprite, 0.2, {alpha:0});
TweenLite.to(myCloseBtn, 0.2, {alpha:0});
TweenLite.to(mySpinBtn, 0.2, {alpha:0});
TweenLite.to(myBuyBtn, 0.2, {alpha:0});
removeChild(myBuyBtn);
removeChild(myCloseBtn);
removeChild(mySpinBtn);
}
contact_mc.contact1.closecontact_btn.addEventListener(MouseEvent.CLICK, closecontact);
contact_mc.contact1.closecontact_btn.buttonMode=true;
contact_btn.removeEventListener(MouseEvent.CLICK, gotocontact);
terms_btn.removeEventListener(MouseEvent.CLICK, gototerms);
about_btn.removeEventListener(MouseEvent.CLICK, gotoabout);
}
function closecontact(event:MouseEvent):void {
contact_mc.gotoAndStop(1);
if (full_mc) {
setChildIndex(full_mc, 1);
TweenLite.to(full_description, 0.5, {alpha:1});
TweenLite.to(full_caption, 0.5, {alpha:1});
TweenLite.to(full_price, 0.5, {alpha:1});
TweenLite.to(medium_price, 0.5, {alpha:1});
TweenLite.to(colour_opt1sprite, 0.5, {alpha:1});
TweenLite.to(colour_opt2sprite, 0.5, {alpha:1});
TweenLite.to(myCloseBtn, 0.5, {alpha:1});
TweenLite.to(mySpinBtn, 0.5, {alpha:1});
TweenLite.to(myBuyBtn, 0.5, {alpha:1});
addChild(myBuyBtn);
addChild(myCloseBtn);
addChild(mySpinBtn);
} else {
setChildIndex(container_mc, 1);
}
contact_btn.addEventListener(MouseEvent.CLICK, gotocontact);
terms_btn.addEventListener(MouseEvent.CLICK, gototerms);
about_btn.addEventListener(MouseEvent.CLICK, gotoabout);
}
terms_btn.addEventListener(MouseEvent.CLICK, gototerms);
function gototerms(event:MouseEvent):void {
terms_mc.gotoAndPlay(2);
if (container_mc) {
setChildIndex(container_mc, 0);
}
if (full_mc) {
setChildIndex(full_mc, 0.1);
setChildIndex(container_mc, 0);
TweenLite.to(full_description, 0.2, {alpha:0});
TweenLite.to(full_caption, 0.2, {alpha:0});
TweenLite.to(full_price, 0.2, {alpha:0});
TweenLite.to(medium_price, 0.2, {alpha:0});
TweenLite.to(colour_opt1sprite, 0.2, {alpha:0});
TweenLite.to(colour_opt2sprite, 0.2, {alpha:0});
TweenLite.to(myCloseBtn, 0.2, {alpha:0});
TweenLite.to(mySpinBtn, 0.2, {alpha:0});
TweenLite.to(myBuyBtn, 0.2, {alpha:0});
removeChild(myBuyBtn);
removeChild(myCloseBtn);
removeChild(mySpinBtn);
}
terms_mc.alpha=.9;
terms_mc.terms1.closeterms_btn.addEventListener(MouseEvent.CLICK, closeterms);
terms_mc.terms1.closeterms_btn.buttonMode=true;
contact_btn.removeEventListener(MouseEvent.CLICK, gotocontact);
terms_btn.removeEventListener(MouseEvent.CLICK, gototerms);
about_btn.removeEventListener(MouseEvent.CLICK, gotoabout);
}
function closeterms(event:MouseEvent):void {
terms_mc.gotoAndStop(1);
if (full_mc) {
setChildIndex(full_mc, 1);
TweenLite.to(full_description, 0.5, {alpha:1});
TweenLite.to(full_caption, 0.5, {alpha:1});
TweenLite.to(full_price, 0.5, {alpha:1});
TweenLite.to(medium_price, 0.5, {alpha:1});
TweenLite.to(colour_opt1sprite, 0.5, {alpha:1});
TweenLite.to(colour_opt2sprite, 0.5, {alpha:1});
TweenLite.to(myCloseBtn, 0.5, {alpha:1});
TweenLite.to(mySpinBtn, 0.5, {alpha:1});
TweenLite.to(myBuyBtn, 0.5, {alpha:1});
addChild(myBuyBtn);
addChild(myCloseBtn);
addChild(mySpinBtn);
} else {
setChildIndex(container_mc, 1);
}
contact_btn.addEventListener(MouseEvent.CLICK, gotocontact);
terms_btn.addEventListener(MouseEvent.CLICK, gototerms);
about_btn.addEventListener(MouseEvent.CLICK, gotoabout);
}
about_btn.addEventListener(MouseEvent.CLICK, gotoabout);
function gotoabout(event:MouseEvent):void {
about_mc.gotoAndPlay(2);
about_mc.alpha=.9;
if (container_mc) {
setChildIndex(container_mc, 0);
}
if (full_mc) {
setChildIndex(full_mc, 0.1);
setChildIndex(container_mc, 0);
TweenLite.to(full_description, 0.2, {alpha:0});
TweenLite.to(full_caption, 0.2, {alpha:0});
TweenLite.to(full_price, 0.2, {alpha:0});
TweenLite.to(medium_price, 0.2, {alpha:0});
TweenLite.to(colour_opt1sprite, 0.2, {alpha:0});
TweenLite.to(colour_opt2, 0.2, {alpha:0});
TweenLite.to(myCloseBtn, 0.2, {alpha:0});
TweenLite.to(mySpinBtn, 0.2, {alpha:0});
TweenLite.to(myBuyBtn, 0.2, {alpha:0});
removeChild(myBuyBtn);
removeChild(myCloseBtn);
removeChild(mySpinBtn);
removeChild(full_description);
removeChild(full_caption);
removeChild(full_price);
removeChild(medium_price);
removeChild(colour_opt1sprite);
removeChild(colour_opt2sprite);
}
about_mc.about1.closeabout_btn.addEventListener(MouseEvent.CLICK, closeabout);
about_mc.about1.closeabout_btn.buttonMode=true;
contact_btn.removeEventListener(MouseEvent.CLICK, gotocontact);
terms_btn.removeEventListener(MouseEvent.CLICK, gototerms);
about_btn.removeEventListener(MouseEvent.CLICK, gotoabout);
}
function closeabout(event:MouseEvent):void {
about_mc.gotoAndStop(1);
if (full_mc) {
setChildIndex(full_mc, 1);
TweenLite.to(full_description, 0.5, {alpha:1});
TweenLite.to(full_caption, 0.5, {alpha:1});
TweenLite.to(full_price, 0.5, {alpha:1});
TweenLite.to(medium_price, 0.5, {alpha:1});
TweenLite.to(colour_opt1sprite, 0.5, {alpha:1});
TweenLite.to(colour_opt2sprite, 0.5, {alpha:1});
TweenLite.to(myCloseBtn, 0.5, {alpha:1});
TweenLite.to(mySpinBtn, 0.5, {alpha:1});
TweenLite.to(myBuyBtn, 0.5, {alpha:1});
addChild(myBuyBtn);
addChild(myCloseBtn);
addChild(mySpinBtn);
addChild(full_description);
addChild(full_price);
addChild(medium_price);
addChild(colour_opt1sprite);
addChild(colour_opt2sprite);
addChild(full_caption);
}
else {
setChildIndex(container_mc, 1);
}
contact_btn.addEventListener(MouseEvent.CLICK, gotocontact);
terms_btn.addEventListener(MouseEvent.CLICK, gototerms);
about_btn.addEventListener(MouseEvent.CLICK, gotoabout);
}
function processXML(e:Event):void {
var myXML:XML=new XML(e.target.data);
columns=myXML.@COLUMNS;
my_x=myXML.@XPOSITION;
my_y=myXML.@YPOSITION;
my_thumb_width=myXML.@WIDTH;
my_thumb_height=myXML.@HEIGHT;
my_images=myXML.IMAGE;
my_total=my_images.length();
createContainer();
callThumbs();
myXMLLoader.removeEventListener(Event.COMPLETE,processXML);
myXMLLoader=null;
}
function createContainer():void {
container_mc = new MovieClip();
container_mc.x=my_x;
container_mc.y=my_y;
addChild(container_mc);
setChildIndex(container_mc, 1);
container_mc.addEventListener(MouseEvent.CLICK,callFull);
container_mc.buttonMode=true;
}
function callThumbs():void {
for (var i:Number = 0; i < my_total; i++) {
var thumb_url=my_images*.@THUMB;
var thumb_loader = new Loader();
var format:TextFormat = new TextFormat();
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,thumbLoaded);
thumb_loader.name=i;
thumb_loader.x = (my_thumb_width)*x_counter;
thumb_loader.y = (my_thumb_height)*y_counter;
thumb_caption=new TextField();
thumb_caption.autoSize="left";
thumb_caption.text=my_images*.@NAME;
thumb_caption.name=String(i);
thumb_caption.selectable=false;
thumb_caption.embedFonts=true;
format.font=myFont.fontName;
format.color=0xFFFFFF;
format.size=9;
format.align="right";
thumb_caption.setTextFormat(format);
thumb_caption.x = (thumb_loader.x+my_thumb_width*.5)-(78);
thumb_caption.y=thumb_loader.y+72;
container_mc.addChild(thumb_caption);
if (x_counter+1<columns) {
x_counter++;
} else {
x_counter=0;
y_counter++;
}
TweenLite.to(thumb_caption, 0, {alpha:0});
thumb_loader.addEventListener(MouseEvent.MOUSE_OVER, showthumbcaption);
function showthumbcaption(event:MouseEvent):void {
TweenLite.to(thumb_caption, 0.5, {alpha:1});
}
thumb_loader.addEventListener(MouseEvent.MOUSE_OUT, hidethumbcaption);
function hidethumbcaption(event:MouseEvent):void {
TweenLite.to(thumb_caption, 0.5, {alpha:0});
}
}
}
function thumbLoaded(e:Event):void {
var my_thumb:Loader=Loader(e.target.loader);
container_mc.addChildAt(my_thumb, 0);
my_tweens[Number(my_thumb.name)]=new Tween(my_thumb,"alpha",Strong.easeIn,0,1,0.5,true);
my_thumb.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoaded);
if (x_counter+1<columns) {
x_counter++;
} else {
x_counter=0;
y_counter++;
}
}
function callFull(e:MouseEvent):void {
var full_loader:Loader = new Loader();
fullImage=full_loader;
var full_url=my_images[e.target.name].@FULL;
spin_url=my_images[e.target.name].@LINK;
shop_url=my_images[e.target.name].@SHOP;
full_loader.load(new URLRequest(full_url));
full_loader.contentLoaderInfo.addEventListener(Event.INIT, fullLoaded);
full_caption.text=my_images[e.target.name].@NAME;
full_description.text=my_images[e.target.name].@DESCRIPTION;
full_price.text=my_images[e.target.name].@LARGEPRICE;
medium_price.text=my_images[e.target.name].@MEDIUMPRICE;
colour_opt1.text=my_images[e.target.name].@COLOPT1;
colour_opt2.text=my_images[e.target.name].@COLOPT2;
container_mc.removeEventListener(MouseEvent.CLICK,callFull);
container_mc.buttonMode=false;
}
function fullLoaded(e:Event):void {
var container_mc:MovieClip;
full_mc = new MovieClip();
addChild(full_mc);
var my_loader:Loader=Loader(e.target.loader);
TweenLite.to(my_loader, 0, {alpha:0});
full_mc.addChild(my_loader);
TweenLite.to(my_loader, 1, {alpha:1});
my_loader.x=0;
my_loader.y=60;
addChild(myBuyBtn);
myBuyBtn.x=475;
myBuyBtn.y=485;
myBuyBtn.buttonMode=true;
myBuyBtn.addEventListener(MouseEvent.CLICK,gotoShop);
addChild(myCloseBtn);
myCloseBtn.x=660;
myCloseBtn.y=485;
myCloseBtn.buttonMode=true;
myCloseBtn.addEventListener(MouseEvent.CLICK,removeFull);
addChild(mySpinBtn);
mySpinBtn.x=560;
mySpinBtn.y=485;
mySpinBtn.buttonMode=true;
mySpinBtn.addEventListener(MouseEvent.CLICK,play360);
function play360(event:MouseEvent):void {
navigateToURL(new URLRequest(spin_url));
}
function gotoShop(event:MouseEvent):void {
navigateToURL(new URLRequest(shop_url));
}
var format:TextFormat = new TextFormat();
format.font=myFont.fontName;
format.size=13;
format.color=0xA3A2A0;
format.align="left";
full_caption.x=610;
full_caption.y=130;
full_caption.selectable=false;
full_caption.embedFonts=true;
full_caption.setTextFormat(format);
addChild(full_caption);
TweenLite.from(full_caption, 2, {alpha:0});
var format2:TextFormat = new TextFormat();
format2.font=myFont.fontName;
format2.size=10;
format2.color=0xA3A2A0;
format2.align="left";
full_description.x=610;
full_description.y=150;
full_description.width=150;
full_description.height=200;
full_description.border=false;
full_description.multiline=true;
full_description.wordWrap=true;
full_description.selectable=false;
full_description.embedFonts=true;
full_description.setTextFormat(format2);
addChild(full_description);
TweenLite.from(full_description, 2.3, {alpha:0});
full_price.x=610;
full_price.y=250;
full_price.selectable=false;
full_price.embedFonts=true;
full_price.setTextFormat(format2);
addChild(full_price);
TweenLite.from(full_price, 2.6, {alpha:0});
medium_price.x=610;
medium_price.y=265;
medium_price.selectable=false;
medium_price.embedFonts=true;
medium_price.setTextFormat(format2);
addChild(medium_price);
TweenLite.from(medium_price, 2.6, {alpha:0});
[COLOR=Magenta]//This is where i create the 2 sprites containing the dynamic text and format it[/COLOR]
[COLOR=Red] colour_opt1.selectable=false;
colour_opt1.embedFonts=true;
colour_opt1.setTextFormat(format2);
colour_opt1.mouseEnabled = false;
//Sprite
var colour_opt1sprite:Sprite = new Sprite();
colour_opt1sprite.buttonMode=true;
colour_opt1sprite.x=610;
colour_opt1sprite.y=350;
colour_opt1.width=50;
colour_opt1.height=15;
colour_opt1sprite.addChild(colour_opt1);
addChild(colour_opt1sprite);
colour_opt2.selectable=false;
colour_opt2.embedFonts=true;
colour_opt2.setTextFormat(format2);
colour_opt2.mouseEnabled = false;
//Sprite
var colour_opt2sprite:Sprite = new Sprite();
colour_opt2sprite.buttonMode=true;
colour_opt2sprite.x=610;
colour_opt2sprite.y=370;
colour_opt2.width=50;
colour_opt2.height=15;
colour_opt2sprite.addChild(colour_opt2);
addChild(colour_opt2sprite);[/COLOR]
TweenLite.from(colour_opt1, 2.6, {alpha:0});
my_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, fullLoaded);
}
function removeFull(e:MouseEvent):void {
var my_loader:Loader=fullImage;
full_tween=new Tween(my_loader,"alpha",Strong.easeOut,1,0,1,true);
full_tween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished);
removeChild(full_description);
removeChild(full_caption);
removeChild(full_price);
removeChild(medium_price);
[COLOR=Magenta]//This is what won't work![/COLOR]
[COLOR=Red] removeChild(colour_opt1sprite);
removeChild(colour_opt2sprite);[/COLOR]
removeChild(myCloseBtn);
removeChild(mySpinBtn);
removeChild(myBuyBtn);
}
function tweenFinished(e:TweenEvent):void {
var my_loader:Loader=Loader(e.target.obj);
my_loader.unload();
full_mc.removeChild(my_loader);
removeChild(full_mc);
full_mc=null;
container_mc.addEventListener(MouseEvent.CLICK, callFull);
container_mc.buttonMode=true;
var my_tween:Tween=Tween(e.target);
my_tween.removeEventListener(TweenEvent.MOTION_FINISH, tweenFinished);
setChildIndex(container_mc, 1);
}
function untweenFinished(e:TweenEvent):void {
removeChild(full_mc);
var tweento360:Tween=Tween(e.target);
tweento360.removeEventListener(TweenEvent.MOTION_FINISH, untweenFinished);
}