我在舞台上遇到addChild的问题。由于某种原因,代码正在跟踪结果,但它没有添加Child,孩子只是一个位于库中的图片文件。它被导入到另一个类文件中。
感谢您的时间。
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;
public class Listingdetailinfo extends MovieClip
{
private var somedata:Array;
public function Listingdetailinfo(somedata:Array)
{
trace("John");
trace("Ben");
trace("Top");
trace("Benson");
var Bolder:Listing8 = new Listing8();
addChild(Bolder);
}
}
}
listingdetail类
package com.clark
{
import com.clark.Listingdetailinfo;
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
import fl.controls.Button;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Listingdetail extends MovieClip
{
public var s1:List = new List ();
private var somedata:Array;
public function Listingdetail()
{
addEventListener(Event.ADDED_TO_STAGE, onadded);
function onadded (event:Event):void
{
s1.x=-10;
s1.y=10;
addChild(s1);
}
function teee():void
{
var tee:Listingdetailinfo = new Listingdetailinfo();
addChild(tee);
}
}
}
}
感谢您的时间
编辑: 来自SearchVectorTest
public var lists:Array;
lists =new Array (test[index].nobed,test[index].zip,test[index].Location,test[index].price);
var addto:Listingdetailinfo = new Listingdetailinfo(lists);
在Listingdetailinfo
中public var lists:Array;
public function Listingdetailinfo(lists:Array) {
trace("Ben");
addChild(Holder);
}
答案 0 :(得分:2)
你的代码是一团糟,这是肯定的。如果您有可以在库中导出的内容,那么这应该有效:
var bolder:Listing8 = new Listing8();
addChild(bolder);
trace(bolder);
trace(bolder.parent);
trace(contains(bolder));
trace(bolder.stage);//will be non null when this and it's containers are on stage
if(bolder.parent) trace(bolder.parent.parent);
单独导入类没有任何作用,只是添加了类的代码,你必须通过实例化它来使用它
var detailInfo:Listingdetailinfo = new Listingdetailinfo();
addChild(detailInfo);