ActionScript 3中的动态文本字段属性设置

时间:2011-07-27 20:29:38

标签: flash actionscript-3

我创建了一个3D墙,我正在传递图像并通过xml进行链接。现在我添加了描述,但它只显示在中间。我不知道如何对齐它。鼠标悬停时,该照片的描述应该在那里显示,但不会显示在中间(对于所有照片)。

这是我的完整代码:

var name1:TextField = new TextField();
addChild(name1);

var xmlReq:URLRequest = new URLRequest("XML/ImagesData01.xml"); // rename to your file!!!
var xmlLoader:URLLoader = new URLLoader();

function imagerollover(e:MouseEvent):void
{
//var mXML:XML;
name1.text = myXML.data[Number(e.currentTarget.name)].@description;  

//var imagesprite:Sprite = e.target as Sprite;
//if(showimage == true) {

} 

我该怎么做?

我附上了图片,突出显示了椭圆形,文字正在显示在那里,但我想让它显示在每个图像上,无论我把鼠标移到哪里

`stop();

 import fl.transitions.Tween;
 import fl.transitions.easing.*;
 import flash.display.Sprite; 
 import flash.events.MouseEvent;
import flash.display.*;
import flash.events.Event;
import flash.display.Shape;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.events.Event;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.geom.ColorTransform;
import flash.net.navigateToURL;

import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.BitmapMaterial;
import flash.text.TextField;


var container:Sprite = new Sprite();
container.x = 0;
container.y = 0;
addChild(container);

var scene:Scene3D = new MovieScene3D(container);
var cam:Camera3D = new Camera3D();
var new_zoom:Number;
cam.zoom = 6;

var planedictionary:Dictionary = new Dictionary();
var imageplane:Plane = new Plane();
imageplane.visible = false;
cam.target = imageplane;

var maxRows:Number = 1;
var yaxis:Number = 0;
var anglenumber:Number = 100;

var image = new Array();
var urllink = new Array();
var urltarget:Array = new Array();
var planes = new Array();

var i:Number;
var max:Number;
var li:Number = 0;
var center:Number = 6.4;
var zoom:Number = 10;
var cameramove:Boolean = true;
var camerapositionX:Number;
var camerapositionY:Number;
var showimage:Boolean = true;
var imageholder;
var xposition:Number;
var yposition:Number;
var zoomdistance:Number = 12;
var name1:TextField = new TextField();
addChild(name1);
name1.x = 100;
name1.y = 20;
name1.textColor = 0xffffff;




var XML_Load:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("XML/ImagesData01.xml"));
loader.addEventListener(Event.COMPLETE, imagecontainer);

function imagecontainer(e:Event):void  {
    XML_Load = XML(e.target.data);
    max = XML_Load.data.length();
    var displayimage:Number = Math.ceil(max/1);
    var anglenumberMath:Number = ((Math.PI*2) * maxRows) / max;

    for(i = 0; i < max; i++) {
        image.push(XML_Load.data[i].@imagepath.toString());
        urllink.push(XML_Load.data[i].@url.toString());
        urltarget.push(XML_Load.data[i].@target.toString());

        var bfm:BitmapFileMaterial = new BitmapFileMaterial("IMAGES/" + XML_Load.data[i].@imagepath.toString());
        bfm.oneSide = true;
        bfm.smooth = true;

        var plane:Plane = new Plane(bfm, 130, 105, 1, 1);
        scene.addChild(plane);
        planes.push(plane);



        var planeMC:Sprite = plane.container;
        planeMC.name = "" + i;
        planedictionary[planeMC] = plane;

        planeMC.buttonMode = true;
        planeMC.addEventListener(MouseEvent.ROLL_OVER, imagerollover);
        planeMC.addEventListener(MouseEvent.ROLL_OUT, imagerollout);
        planeMC.addEventListener(MouseEvent.CLICK, imagepress);

        camerapositionX = ((150 * displayimage) - 150) * 0.5;
        camerapositionY = ((115 * maxRows) - 115) * 0.5;

        plane.x = li * 150 - camerapositionX;
        li++; 
        plane.y = yaxis - camerapositionY;

        if((i+1) % displayimage == 0) {
             li = 0;
             yaxis += 115;
        }
    }
};


var xmlReq:URLRequest = new URLRequest("XML/ImagesData01.xml"); // rename to your file!!!
var xmlLoader:URLLoader = new URLLoader();
//var myXML:XML;





//-----------------


//xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded); // event listener b4 load!!!
//xmlLoader.load(xmlReq);

//var myXML:XML;
//var mySprite:Sprite;
//var headLoader:Loader;


//function imagerollover(e:MouseEvent):void  
//{
//navigateToURL(new URLRequest(String(myXML.data[Number(e.currentTarget.name)].@description)));

//}


//function xmlLoaded(e:Event):void{
//myXML = new XML(e.target.data);
//for (var i:int = 0; i < myXML.children().length(); i++)
//{
//headLoader = new Loader();
//mySprite = new Sprite();
//headLoader.load(new URLRequest(String(myXML.data[i].@description)));
//mySprite.addChild(headLoader);
//mySprite.name = String(i);
//mySprite.addEventListener(MouseEvent.ROLL_OVER, imagerollover)
//addChild(mySprite);
//}

//}


//-------------------


function imagerollover(e:MouseEvent):void
{
    //var mXML:XML;
    name1.text = myXML.data[Number(e.currentTarget.name)].@description;  

    //var imagesprite:Sprite = e.target as Sprite;
    //if(showimage == true) {

    } 
    //};

function imagerollout(e:MouseEvent) {
    var imagesprite:Sprite = e.target as Sprite;
    if(showimage == true) {

    }
};








xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded); // event listener b4 load!!!
xmlLoader.load(xmlReq);

var myXML:XML;
var mySprite:Sprite;
var headLoader:Loader;


function imagepress(e:MouseEvent):void  
{
navigateToURL(new URLRequest(String(myXML.data[Number(e.currentTarget.name)].@url)),"_self");

}


function xmlLoaded(e:Event):void{
myXML = new XML(e.target.data);
for (var i:int = 0; i < myXML.children().length(); i++)
{
headLoader = new Loader();
mySprite = new Sprite();
headLoader.load(new URLRequest(String(myXML.data[i].@image)));
mySprite.addChild(headLoader);
mySprite.name = String(i);
mySprite.addEventListener(MouseEvent.CLICK, imagepress)
addChild(mySprite);
}


}



stage.addEventListener(MouseEvent.MOUSE_WHEEL, CameraZoom);

function CameraZoom(e:MouseEvent) {
    var newzoom:Number = zoomdistance + e.delta/5;

    if(newzoom < 3) {
        newzoom = 3
    }

    if(newzoom > 18) {
        newzoom = 18
    }

    zoomdistance = newzoom;
};

addEventListener(Event.ENTER_FRAME, render);

function render(e:Event):void {
    cam.zoom += (zoomdistance - cam.zoom)/5;

    if(cameramove == true) {
        cam.x += (((stage.mouseX-(stage.stageWidth * 0.5))*2)-cam.x) * 0.05;
        cam.y += (((stage.mouseY-(stage.stageHeight * 0.5))*2)-cam.y) * 0.05;
    }

    scene.renderCamera(cam);
};`

2 个答案:

答案 0 :(得分:0)

据我所知,你的问题基本上是“如何重新定位TextField?”。所以没有任何细节我会回答。

TextField对象具有xy属性,可以更改其位置。只需将它们设置为您想要的值即可。

name1.x = 100;
name1.y = 20;

答案 1 :(得分:0)

imagerollover函数中设置x和y位置。

可能会有效。

name1.x = e.currentTarget.x;
name1.y = e.currentTarget.y;