@Yaroslav Mate
我把问题转移到了这个新问题上。我正在尝试在加载图像时删除loading111。 我想要做的是,将load111添加到每个Bolder中,当图像加载时,我删除了loading111(这只是一个显示加载的标志)。
感谢您的帮助!
for (var k:int = 0; k < test.length; k++)
{
var Bolder:Listing8 = new Listing8();
Bolder.x=20;
if(test[k].pic1){
var loader:Loader = new Loader();
var loading111:loading1 = new loading1;
Bolder.addChild(loading111);
loader.load(new
URLRequest("http://www.rentaid.info/rent/"+test[k].pic1));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
Bolder.addChild(loader);
}
function onImageLoaded(e:Event):void {
e.currentTarget.loader.content.height =50;
e.target.content.x = 130;
e.target.content.y = 15;
e.target.content.height = 70;
e.target.content.width = 140;
var bf:TextField = new TextField();
var bf1:TextField = new TextField();
var bf2:TextField = new TextField();
var bf3:TextField = new TextField();
bf3.width = 100;
bf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);
bf.width = 100;
bf.autoSize = TextFieldAutoSize.CENTER;
bf1.width = 100;
bf1.autoSize = TextFieldAutoSize.CENTER;
bf2.autoSize = TextFieldAutoSize.CENTER;
bf3.autoSize = TextFieldAutoSize.CENTER;
bf3.width = 100;
bf1.y= bf.height+5;
// Pulling the textfields content out from the current bookVO
bf.text = test[k].nobed;
bf1.text = test[k].zip;
bf2.text = test[k].Location;
bf3.text = test[k].price;
bf.x = (Bolder.height-bf.height)*.2
Bolder.addChild(bf);
Bolder.addChild(bf1);
Bolder.addChild(bf2);
Bolder.addChild(bf3);
// position the object based on the accumulating variable.
Bolder.y = currentY;
Bolder.mouseChildren = false; // ignore children mouseEvents
Bolder.mouseEnabled = true; // enable mouse on the object - normally set to true by default
Bolder.useHandCursor = true; // add hand cursor on mouse over
Bolder.buttonMode = true;
trace ('add image with index', k);
image[k]= new Sprite();
image[k].addChild(Bolder);
image.mouseChildren = true; // ignore children mouseEvents
image.mouseEnabled = true; // enable mouse on the object - normally set to true by default
image.useHandCursor = true; // add hand cursor on mouse over
image.buttonMode = true;
image[k].addEventListener(MouseEvent.CLICK, gotoscene);
currentY += Bolder.height + 10;
}
if( test.length > 0 )
{
_contentHolder = new Sprite();
addChild(_contentHolder);
for (var j:int = 0; j < test.length; j++) {
_contentHolder.addChild(image[j]);
}
编辑:
package com.clark
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.Sprite;
import flash.display.*;
public class SearchVectorTest extends MovieClip
{
public var listings:Vector.<Listing8>;
public var _contentHolder: Sprite= new Sprite;;
public var id:String;
public var nobed:String;
public var zip:String;
public var Location:String;
public var price:String;
public var pic1:String;
public var pic2:String;
public var pic3:String;
public var loadedArray:Array = new Array;
public var callMethod:Function;
private var image:Array = new Array;
private var sprite:Sprite = new Sprite;
public var newArray:Array = new Array;
public var Bolder:Listing8 = new Listing8();
public var index:Number;
public static var lists:Array;
public function SearchVectorTest(test:Vector.<searchVO1>)
{
GLOBALS.resultholder1 = this;
for (var j:int = 0; j < test.length; j++)
{
trace(test[j].id);
trace(test[j].nobed);
trace(test[j].zip);
trace(test[j].Location);
trace(test[j].price);
trace(test[j].pic1);
trace(test[j].pic2);
trace(test[j].pic3);
}
var currentY:int = 100;
for (var k:int = 0; k < test.length; k++)
{
var Bolder:Listing8 = new Listing8();
Bolder.x=20;
if(test[k].pic1){
var loader:Loader = new Loader();
var loading111:loading1 = new loading1;
loader.load(new URLRequest("http://www.rentaid.info/rent/"+test[k].pic1));
Bolder.addChild(loading111);
Bolder.addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
}
function onImageLoaded(e:Event):void {
e.target.content.x = 130;
e.target.content.y = 15;
e.target.content.height = 70;
e.target.content.width = 140;
var boulderOfThisImage = e.target.parent;
while(boulderOfThisImage.numChildren){
boulderOfThisImage.removeChildAt(0);
}
boulderOfThisImage.addChild(e.target);
}
var bf:TextField = new TextField();
var bf1:TextField = new TextField();
var bf2:TextField = new TextField();
var bf3:TextField = new TextField();
bf3.width = 100;
bf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);
bf.width = 100;
bf.autoSize = TextFieldAutoSize.CENTER;
bf1.width = 100;
bf1.autoSize = TextFieldAutoSize.CENTER;
bf2.autoSize = TextFieldAutoSize.CENTER;
bf3.autoSize = TextFieldAutoSize.CENTER;
bf3.width = 100;
bf1.y= bf.height+5;
// Pulling the textfields content out from the current bookVO
bf.text = test[k].nobed;
bf1.text = test[k].zip;
bf2.text = test[k].Location;
bf3.text = test[k].price;
bf.x = (Bolder.height-bf.height)*.2
Bolder.addChild(bf);
Bolder.addChild(bf1);
Bolder.addChild(bf2);
Bolder.addChild(bf3);
// position the object based on the accumulating variable.
Bolder.y = currentY;
Bolder.mouseChildren = false; // ignore children mouseEvents
Bolder.mouseEnabled = true; // enable mouse on the object - normally set to true by default
Bolder.useHandCursor = true; // add hand cursor on mouse over
Bolder.buttonMode = true;
trace ('add image with index', k);
image[k]= new Sprite();
image[k].addChild(Bolder);
image.mouseChildren = true; // ignore children mouseEvents
image.mouseEnabled = true; // enable mouse on the object - normally set to true by default
image.useHandCursor = true; // add hand cursor on mouse over
image.buttonMode = true;
image[k].addEventListener(MouseEvent.CLICK, gotoscene);
currentY += Bolder.height + 10;
}
if( test.length > 0 )
{
_contentHolder = new Sprite();
addChild(_contentHolder);
for (var j:int = 0; j < test.length; j++) {
_contentHolder.addChild(image[j]);
}
newArray.push(image);
var viewport:Viewport = new Viewport();
viewport.y = 0;
viewport.addChild(_contentHolder);
var scroller:TouchScroller = new TouchScroller();
scroller.width = 300;
scroller.height = 265;
scroller.x = 10;
scroller.y = 100;
scroller.viewport = viewport;
addChild(scroller);
}
function gotoscene(e: MouseEvent):void{
}
答案 0 :(得分:1)
removeChild之(loading111);尝试从“this”类中删除最后创建的加载器图标,而不是从Boulder类对象中删除。
您应该将图像和其他显示对象存储在像Vector这样的容器中,并通过id访问它们。
但是有一个粗略的解决方案,如果你不小心可能会给你带来一些问题:
function onImageLoaded(e:Event):void {
DisplayObjectContainer(e.target.loader).parent.removeChildAt(0);
或者如果它不起作用那么:
function onImageLoaded(e:Event):void {
var boulderOfThisImage:DisplayObjectContainer = DisplayObjectContainer(e.target.loader).parent;
while(boulderOfThisImage.numChildren){
boulderOfThisImage.removeChildAt(0);
}
boulderOfThisImage.addChild(e.target);
我非常反对使用removeChildAt函数。更改显示列表结构后,可能会导致许多问题。但它的确有效。