问题描述
@Yaroslav Mate
@Yaroslav Mate
我把问题移到了这个新问题上.我正在尝试在加载图像时删除loading111.我正在尝试做的是,将loading111添加到每个Bolder中,并且在加载图像时,我删除了loading111(这只是一个显示正在加载的标志).
I moved the question to this new one. I am trying to remove the loading111 when the image is loaded.What i am trying to do, to add loading111 into each Bolder, and when the image is loaded, and i remove the loading111(which is just a sign showing loading).
感谢您的帮助!
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{
}
推荐答案
removeChild(loading111);尝试从这个"类而不是Boulder类对象中删除最后创建的加载程序图标.
removeChild(loading111); tries to remove last created loader icon from "this" class and not from Boulder class object.
您应该将图像和其他显示对象存储在Vector之类的容器中,并通过ID对其进行访问.
You should store your images and other display objects in come container like Vector and access them by id.
但是有一个粗略的解决方案,如果您粗心的话,可能会导致一些问题:
But there is rough solution, which may cause you some problems if you will be careless:
function onImageLoaded(e:Event):void {
DisplayObjectContainer(e.target.loader).parent.removeChildAt(0);
或者如果它不起作用,则:
or if it does not work then:
function onImageLoaded(e:Event):void {
var boulderOfThisImage:DisplayObjectContainer = DisplayObjectContainer(e.target.loader).parent;
while(boulderOfThisImage.numChildren){
boulderOfThisImage.removeChildAt(0);
}
boulderOfThisImage.addChild(e.target);
我强烈反对使用removeChildAt函数.更改显示列表结构后,可能会导致许多问题.但这行得通.
I highly disapprove using removeChildAt function. It may cause many problems after changing your display list structure. But it works.
这篇关于删除在循环中添加的parent.AddChild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!