ok voy a aclararles el codigo
El codigo esta bien...
Código ActionScript :
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.events.Event;
import flash.net.URLRequest;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event):void
{
tx.text = String(loader.data.myVar); //jala el texto desde un .txt
tx1.text = String(loader.data.myVar1);//jala el texto desde un .txt
tx2.text = String(loader.data.myVar2);//jala el texto desde un .txt
tx3.text = String(loader.data.myVar3);//jala el texto desde un .txt
tx4.text = String(loader.data.myVar4);//jala el texto desde un .txt
tx5.text = String(loader.data.myVar5);//jala el texto desde un .txt
}
loader.load(new URLRequest("data.txt"));
el txt lo deben de llamar data.txt
y quedaria asi...
Nota: deben de poner los textbox manualmente y en propiedades nombrarlos como tx,t1,tx2..tx5
Código :
myVar=cara 0&myVar1=cara 1&myVar2=cara 2&myVar3=cara 3&myVar4=cara 4&myVar5=cara5
EL CODIGO ESTA MUY BIEN PARA LOS QUE NECESITEN JALAR CODIGO DESDE UN ARCHIVO TXT EXTERNO EN SU APLICACION FLASH
EL PROBLEMA QUE YO TENGO ES ESTE...
Tengo un cubo (con 6 caras) cada cara debe mostrar texto externo desde un txt (texto dinamico)
el problema que tengo es que al publicar el codigo que les puse arriba pues simplemente no hace su tareaU_U
mi codigo este...
Código ActionScript :
package com.flashandmath.bitmaps {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.geom.Matrix;
import flash.geom.Point;
import com.flashandmath.bitmaps.ImageLoader;
import com.flashandmath.bitmaps.BitmapTransformer;
public class CubeMenu extends Sprite {
private var imgLoader:ImageLoader;
private var errorBox:TextField;
private var bitmap:BitmapData;
private var bd0:BitmapData;
private var bd1:BitmapData;
private var bd2:BitmapData;
private var bd3:BitmapData;
private var bd4:BitmapData;
private var bd5:BitmapData;
private var bdTransform:BitmapTransformer;
private var vertsArray:Array;
private var facesArray:Array;
private var numVertices:uint;
private var numFaces:uint;
private var boardSize:Number;
private var spBoard:Sprite;
private var shBack:Shape;
private var spCube:Sprite;
private var doRotate:Boolean;
private var prevX:Number;
private var prevY:Number;
private var curTheta:Number;
private var curPhi:Number;
private var cubeSize:Number;
public var fLen:Number;
public var side0:Sprite;
public var side1:Sprite;
public var side2:Sprite;
public var side3:Sprite;
public var side4:Sprite;
public var side5:Sprite;
private var infoBox:TextField;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.text.TextFormatAlign;
public function get kerning():Object{}
public function CubeMenu(imgs:Array,size:Number) {
cubeSize=size;
boardSize=2*cubeSize+20;
setUpInfoBox();
fLen=500;
spBoard=new Sprite();
this.addChild(spBoard);
shBack=new Shape();
spBoard.addChild(shBack);
spCube=new Sprite();
spBoard.addChild(spCube);
spCube.x=boardSize/2;
spCube.y=boardSize/2;
side0=new Sprite();
spCube.addChild(side0);
side1=new Sprite();
spCube.addChild(side1);
side2=new Sprite();
spCube.addChild(side2);
side3=new Sprite();
spCube.addChild(side3);
side4=new Sprite();
spCube.addChild(side4);
side5=new Sprite();
spCube.addChild(side5);
side0.doubleClickEnabled=true;
side1.doubleClickEnabled=true;
side2.doubleClickEnabled=true;
side3.doubleClickEnabled=true;
side4.doubleClickEnabled=true;
side5.doubleClickEnabled=true;
doRotate=false;
curTheta=20;
curPhi=70;
drawBack(0x000000,0x333333,0,boardSize);
prepErrorBox();
prepImgs(imgs);
}
private function drawBack(b:Number,r:Number,t:Number,s:Number):void {
shBack.graphics.clear();
shBack.graphics.lineStyle(t,r);
shBack.graphics.beginFill(b);
shBack.graphics.drawRect(0,0,s,s);
shBack.graphics.endFill();
}
private function prepErrorBox():void {
errorBox=new TextField();
this.addChild(errorBox);
errorBox.wordWrap=true;
errorBox.mouseEnabled=false;
errorBox.background=false;
errorBox.border=false;
setErrorBoxSizeAndPos(300,100,20,20);
setErrorBoxFormat(0x999999,14);
errorBox.text="Cargando...";
errorBox.visible=true;
}
private function prepImgs(a:Array):void {
imgLoader=new ImageLoader();
imgLoader.addEventListener(ImageLoader.LOAD_ERROR,errorLoading);
imgLoader.addEventListener(ImageLoader.IMGS_LOADED,allLoaded);
imgLoader.loadImgs(a);
}
private function errorLoading(e:Event):void {
errorBox.visible=true;
errorBox.text="Error en la carga de datos o el servidor se encuentra ocupado, intente refrescar la página.";
}
private function allLoaded(e:Event):void {
errorBox.visible=false;
initApp();
}
private function initApp():void {
var imgsSize:Number;
var tx:TextField = new TextField();
var tx1:TextField = new TextField();
var tx2:TextField = new TextField();
var tx3:TextField = new TextField();
var tx4:TextField = new TextField();
var tx5:TextField = new TextField();
var tf:TextFormat = new TextFormat();
// da formato al texto
tf.size = 25;
tf.color = 0xffffff;
tf.align = TextFormatAlign.CENTER;
tf.kerning = true;
tf.bold = true;
tx.wordWrap = true;
tx1.wordWrap =true ;
tx2.wordWrap =true ;
tx3.wordWrap =true ;
tx4.wordWrap =true ;
tx5.wordWrap =true ;
//posicion del texto
var matrix:Matrix = new Matrix()
var centerY:Number = (200 - tx.height)/ 2;
matrix.translate(0, centerY);
var matrix1:Matrix = new Matrix();
var center1Y:Number = (200 - tx1.height)/ 2;
matrix1.translate(0, center1Y);
var matrix2:Matrix = new Matrix();
var center2Y:Number = (200 - tx2.height)/ 2;
matrix2.translate(0, center2Y);
var matrix3:Matrix = new Matrix();
var center3Y:Number = (200 - tx3.height)/ 2;
matrix3.translate(0, center3Y);
var matrix4:Matrix = new Matrix();
var center4Y:Number = (200 - tx4.height)/ 2;
matrix4.translate(0, center4Y);
var matrix5:Matrix = new Matrix();
var center5Y:Number = (200 - tx5.height)/ 2;
matrix5.translate(0, center5Y);
//posicion del texto
tx.defaultTextFormat = tf;
tx.width = 200;// - (200*2);
tx.selectable = false;
tx.borderColor = 0xffffff;
tx1.defaultTextFormat = tf;
tx1.width = 200;// - (200*2);
tx1.selectable = false;
tx1.borderColor = 0xffffff;
tx2.defaultTextFormat = tf;
tx2.width = 200;// - (200*2);
tx2.selectable = false;
tx2.borderColor = 0xffffff;
tx3.defaultTextFormat = tf;
tx3.width = 200;// - (200*2);
tx3.selectable = false;
tx3.borderColor = 0xffffff;
tx4.defaultTextFormat = tf;
tx4.width = 200;// - (200*2);
tx4.selectable = false;
tx4.borderColor = 0xffffff;
tx5.defaultTextFormat = tf;
tx5.width = 200;// - (200*2);
tx5.selectable = false;
tx5.borderColor = 0xffffff;
// set the default text content
// carga de texto externo
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.events.Event;
import flash.net.URLRequest;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event):void
{
tx.text = String(loader.data.myVar); //jala el texto desde un .txt
tx1.text = String(loader.data.myVar1);//jala el texto desde un .txt
tx2.text = String(loader.data.myVar2);//jala el texto desde un .txt
tx3.text = String(loader.data.myVar3);//jala el texto desde un .txt
tx4.text = String(loader.data.myVar4);//jala el texto desde un .txt
tx5.text = String(loader.data.myVar5);//jala el texto desde un .txt
}
loader.load(new URLRequest("data.txt"));
//tx.text = "Ejdshfkjh";
//tx1.text = "Esquemas de fraude";
//tx2.text = "Proyectos";
//tx3.text = "Vamos a comer al borrego viudo y pediré diez tacos";
//tx4.text = "Negocio";
//tx5.text = "Tengo Hambre y ya es mucha";
// render to a bitmap
var bitmapData:BitmapData = new BitmapData(200, 200, false, 0x000039);
var bitmapData1:BitmapData = new BitmapData(200, 200, false, 0x000031);
var bitmapData2:BitmapData = new BitmapData(200, 200, false, 0x000033);
var bitmapData3:BitmapData = new BitmapData(200, 200, false, 0x000036);
var bitmapData4:BitmapData = new BitmapData(200, 200, false, 0x000040);
var bitmapData5:BitmapData = new BitmapData(200, 200, false, 0x000033);
bitmapData.draw(tx, matrix);
bitmapData1.draw(tx1, matrix1);
bitmapData2.draw(tx2, matrix2);
bitmapData3.draw(tx3, matrix3);
bitmapData4.draw(tx4, matrix4);
bitmapData5.draw(tx5, matrix5);
var bitmap:Bitmap = new Bitmap();
bitmap.smoothing = true;
//addChild(bitmap);
var bitmap1:Bitmap = new Bitmap();
var bitmap2:Bitmap = new Bitmap();
var bitmap3:Bitmap = new Bitmap();
var bitmap4:Bitmap = new Bitmap();
var bitmap5:Bitmap = new Bitmap();
bitmap.bitmapData = bitmapData;
bitmap.smoothing = true;
bitmap1.bitmapData = bitmapData1;
bitmap1.smoothing = true;
bitmap2.bitmapData = bitmapData2;
bitmap2.smoothing = true;
bitmap3.bitmapData = bitmapData3;
bitmap3.smoothing = true;
bitmap4.bitmapData = bitmapData4;
bitmap4.smoothing = true;
bitmap5.bitmapData = bitmapData5;
bitmap5.smoothing = true;
//addChild(bitmap);
bd0=bitmap.bitmapData;
bd1=bitmap1.bitmapData;
bd2=bitmap2.bitmapData;
bd3=bitmap3.bitmapData;
bd4=bitmap4.bitmapData;
bd5=bitmap5.bitmapData;
imgsSize=bd0.width;
bdTransform=new BitmapTransformer(imgsSize,imgsSize,20,20);
vertsArray=[];
facesArray=[];
numVertices=8;
numFaces=6;
setVertices();
setFaces();
renderView(curTheta,curPhi);
setUpListeners();
}
private function setVertices():void {
vertsArray[0]=[cubeSize/1.7,-cubeSize/1.7,cubeSize/1.7];
vertsArray[1]=[cubeSize/1.7,cubeSize/1.7,cubeSize/1.7];
vertsArray[2]=[-cubeSize/1.7,cubeSize/1.7,cubeSize/1.7];
vertsArray[3]=[-cubeSize/1.7,-cubeSize/1.7,cubeSize/1.7];
vertsArray[4]=[cubeSize/1.7,-cubeSize/1.7,-cubeSize/1.7];
vertsArray[5]=[cubeSize/1.7,cubeSize/1.7,-cubeSize/1.7];
vertsArray[6]=[-cubeSize/1.7,cubeSize/1.7,-cubeSize/1.7];
vertsArray[7]=[-cubeSize/1.7,-cubeSize/1.7,-cubeSize/1.7];
}
private function setFaces():void {
facesArray[0]=[0,1,5,4,bd0];
facesArray[1]=[1,2,6,5,bd1];
facesArray[2]=[2,3,7,6,bd2];
facesArray[3]=[3,0,4,7,bd3];
facesArray[4]=[4,5,6,7,bd4];
facesArray[5]=[3,2,1,0,bd5];
}
private function setUpListeners():void {
imgLoader.removeEventListener(ImageLoader.LOAD_ERROR,errorLoading);
imgLoader.removeEventListener(ImageLoader.IMGS_LOADED,allLoaded);
spBoard.addEventListener(MouseEvent.ROLL_OUT,boardOut);
spBoard.addEventListener(MouseEvent.MOUSE_MOVE,boardMove);
spBoard.addEventListener(MouseEvent.MOUSE_DOWN,boardDown);
spBoard.addEventListener(MouseEvent.MOUSE_UP,boardUp);
side0.addEventListener(MouseEvent.CLICK,side0Clicked);
side1.addEventListener(MouseEvent.CLICK,side1Clicked);
side2.addEventListener(MouseEvent.CLICK,side2Clicked);
side3.addEventListener(MouseEvent.CLICK,side3Clicked);
side4.addEventListener(MouseEvent.CLICK,side4Clicked);
side5.addEventListener(MouseEvent.CLICK,side5Clicked);
}
private function boardOut(e:MouseEvent):void {
doRotate=false;
}
private function boardDown(e:MouseEvent):void {
prevX=spBoard.mouseX;
prevY=spBoard.mouseY;
doRotate=true;
}
private function boardUp(e:MouseEvent):void {
doRotate=false;
}
private function boardMove(e:MouseEvent):void {
var locX:Number=prevX;
var locY:Number=prevY;
if(doRotate){
prevX=spBoard.mouseX;
prevY=spBoard.mouseY;
curTheta+=(prevX-locX);
curPhi+=(prevY-locY);
renderView(curTheta,curPhi);
e.updateAfterEvent();
}
}
private function side0Clicked(e:MouseEvent):void {
curTheta=0;
curPhi=90;
renderView(curTheta,curPhi);
//infoBox.text="ESQUEMAS DE FRAUDE";
}
private function side1Clicked(e:MouseEvent):void {
curTheta=-270;
curPhi=90;
renderView(curTheta,curPhi);
//infoBox.text="PROYECTOS";
border = true;
}
private function side2Clicked(e:MouseEvent):void {
curTheta=-180;
curPhi=90;
renderView(curTheta,curPhi);
//infoBox.text="NEGOCIO";
border = true;
}
private function side3Clicked(e:MouseEvent):void {
curTheta=-90;
curPhi=90;
border = true;
borderColor = 000000;
renderView(curTheta,curPhi);
// infoBox.text="PERSONAS";
}
private function side4Clicked(e:MouseEvent):void {
curTheta=0;
curPhi=-180;
renderView(curTheta,curPhi);
//infoBox.text="INCIDENTES DE FRAUDE";
}
private function side5Clicked(e:MouseEvent):void {
curTheta=0;
curPhi=0;
renderView(curTheta,curPhi);
// infoBox.text="CIFRAS";
}
private function setUpInfoBox():void {
var infoFormat:TextFormat=new TextFormat();
infoBox=new TextField();
this.addChild(infoBox);
infoBox.x=347;
infoBox.y=165;
infoBox.width=255;
infoBox.height=100;
infoBox.wordWrap=true;
infoBox.mouseEnabled=false;
infoFormat.color=0x000987;
infoFormat.align="center";
infoFormat.size=14;
infoFormat.font="Bell Gothic Std";
infoBox.defaultTextFormat=infoFormat;
}
private function renderView(t:Number,p:Number):void {
var i:int;
var distArray=[];
var dispArray=[];
var vertsNewArray=[];
var midPoint:Array=[];
var curv0:Array=[];
var curv1:Array=[];
var curv2:Array=[];
var curv3:Array=[];
var curImg:BitmapData;
var dist:Number;
var curFace:uint;
t=t*Math.PI/180;
p=p*Math.PI/180;
side0.graphics.clear();
side1.graphics.clear();
side2.graphics.clear();
side3.graphics.clear();
side4.graphics.clear();
side5.graphics.clear();
for(i=0;i<numVertices;i++){
vertsNewArray[i]=pointNewView(vertsArray[i],t,p);
}
for(i=0;i<numFaces;i++){
midPoint[0]=(vertsNewArray[facesArray[i][0]][0]+vertsNewArray[facesArray[i][1]][0]+vertsNewArray[facesArray[i][2]][0]+vertsNewArray[facesArray[i][3]][0])/4;
midPoint[1]=(vertsNewArray[facesArray[i][0]][1]+vertsNewArray[facesArray[i][1]][1]+vertsNewArray[facesArray[i][2]][1]+vertsNewArray[facesArray[i][3]][1])/4;
midPoint[2]=(vertsNewArray[facesArray[i][0]][2]+vertsNewArray[facesArray[i][1]][2]+vertsNewArray[facesArray[i][2]][2]+vertsNewArray[facesArray[i][3]][2])/4;
dist=Math.sqrt(Math.pow(fLen-midPoint[0],2)+Math.pow(midPoint[1],2)+Math.pow(midPoint[2],2));
distArray[i]=[dist,i];
}
distArray.sort(byDist);
for(i=0;i<numVertices;i++){
dispArray[i]=[fLen/(fLen-vertsNewArray[i][0])*vertsNewArray[i][1],-fLen/(fLen-vertsNewArray[i][0])*vertsNewArray[i][2]];
}
for(i=3;i<numFaces;i++){
curFace=distArray[i][1];
curv0=[dispArray[facesArray[curFace][0]][0],dispArray[facesArray[curFace][0]][1]];
curv1=[dispArray[facesArray[curFace][1]][0],dispArray[facesArray[curFace][1]][1]];
curv2=[dispArray[facesArray[curFace][2]][0],dispArray[facesArray[curFace][2]][1]];
curv3=[dispArray[facesArray[curFace][3]][0],dispArray[facesArray[curFace][3]][1]];
curImg=facesArray[curFace][4];
spCube.setChildIndex(this["side"+String(curFace)],spCube.numChildren-1);
bdTransform.mapBitmapData(curImg,new Point(curv0[0],curv0[1]),new Point(curv1[0],curv1[1]),new Point(curv2[0],curv2[1]),new Point(curv3[0],curv3[1]),this["side"+String(curFace)]);
}
}
private function byDist(v:Array,w:Array):Number {
if (v[0]>w[0]){
return -1;
} else if (v[0]<w[0]){
return 1;
} else {
return 0;
}
}
private function pointNewView(v:Array,theta:Number,phi:Number):Array {
var newCoords:Array=[];
newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
return newCoords;
}
public function setErrorBoxSizeAndPos(w:Number,h:Number,a:Number,b:Number): void {
errorBox.width=w;
errorBox.height=h;
errorBox.x=a;
errorBox.y=b;
}
public function setErrorBoxFormat(colo:Number,s:Number): void {
var errorFormat:TextFormat=new TextFormat();
errorFormat.color=colo;
errorFormat.size=s;
errorFormat.font="Arial";
errorBox.defaultTextFormat=errorFormat;
}
public function setBackLook(b:Number,r:Number,t:Number): void {
drawBack(b,r,t,boardSize);
}
}
}
ayuda porfavor