嗨,我是AS3的新手,仅仅几个月就进入OOP我不知道如何在点击MouseEvent时选择数组或Vector的特定部分。
所以我将一个Vector列表解析为这个名为SearchVectorTest的类,并将它们放入容器中,我试图在包含该部分的特定容器(盒子)时选择Vector的特定部分(即文本)单击文本。这样我就可以将它解析为下一个类文件以供进一步使用。
目前我只知道如何获取点击的部分索引,但是它不起作用。
var clickedpart:listings = Holder.target as Listing8;
var listIndex:uint = listings.indexOf(clickedpart);
trace("You clicked the part at index " + listIndex);
我刚试了这个trace( bf.text+bf1.text+ bf2.text+bf3.text);
它正确地跟踪了最后4个文本,但没有找到我点击的文本。
这是SearchVectorTest的全套
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 SearchVectorTest extends MovieClip
{
public var listings:Vector.<Listing8>;
public var _contentHolder: Sprite;
public function SearchVectorTest(test:Vector.<searchVO1>)
{
for (var j:int = 0; j < test.length; j++)
{
trace(test[j].nobed);
trace(test[j].zip);
trace(test[j].Location);
trace(test[j].price);
}
var james:int = test ? test.length : 0;
listings = new Vector.<Listing8>(james, true);
var currentY:int = 100;
for (var k:int = 0; k < test.length; k++)
{
var Bolder:Listing8 = new Listing8();
Bolder.x=20;
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);
Bolder.properties = test[k].nobed;
Bolder.properties = test[k].zip;
// position the object based on the accumulating variable.
Bolder.y = currentY;
addChild(Bolder);
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;
listings[k] = Bolder;
currentY += Bolder.height + 10;
}
if( listings.length > 0 )
{
_contentHolder = new Sprite();
addChild(_contentHolder);
for (var j:int = 0; j < listings.length; j++) {
_contentHolder.addChild(listings[j]);
}
_contentHolder.addEventListener(MouseEvent.CLICK, gotoscene);
}
function gotoscene(e: MouseEvent):void{
var clickedpart:Listing8 = Bolder.target as Listing8;
var listIndex:uint = listings.indexOf(clickedpart);
trace( bf.text+bf1.text+ bf2.text+bf3.text);
while(_contentHolder.numChildren > 0)
{
_contentHolder.removeChildAt(0);
}
while(GLOBALS.resultholder.numChildren > 0)
{
GLOBALS.resultholder.removeChildren();
}
var s5:Listingdetail= new Listingdetail ();
addChild(s5);
}
}
}
}
感谢您的时间
答案 0 :(得分:0)
function gotoscene(e: MouseEvent):void{
var searchString = listings;
var index:Number;
index = searchString.indexOf(e.target);
trace(test[index].nobed+test[index].zip+test[index].Location+test[index].price);
}