Skip to main content
Participant
March 18, 2015
Answered

ayuda con as3

  • March 18, 2015
  • 1 reply
  • 498 views

Que tal buenas tardes:

Quisiera pedir su apoyo, con el fin de que me ayuden.

Estoy tratando de hacer una botonera en as3 para un proyecto que se me encargo, her realizado los botones y el texto que va en los botones, sin embargo a la hora de ponerles los links, estos no funcionan.

El código que he hecho es el siguiente:

var nombresBotones:Array = new Array ("GOOGLE", "YAHOO", "HOTMAIL", "INTERC", "CRISTALAB");

var direccionesWeb:Array = new Array ("http://www.google.com.mx", "http://www.yahoo.com.mx", "http://www.hotmail.com", "http://www.intercambiosvirtuales.org","http://www.cristalab.com");

for (var i = 0; i<5; i++){

var button:Sprite = new Sprite();

button.graphics.beginFill(0xff0066, 0.5);

button.graphics.drawRect(0, 0, 70, 25);

button.graphics.endFill();

button.x = i * 80;

button.y = 30;

var str:String = nombresBotones;

var fontDescription:FontDescription = new FontDescription("Arial","normal");

var format:ElementFormat = new ElementFormat(fontDescription, 14, 0x000000, 1);

var textElement:TextElement = new TextElement(str.toUpperCase(), format);

var textBlock:TextBlock = new TextBlock();

textBlock.content = textElement;

textBlock.baselineZero = TextBaseline.ROMAN;

var textLine:TextLine = textBlock.createTextLine(null, 300);

textLine.x = 5;

textLine.y = textLine.height+5;

button.buttonMode = true;

addChild (button);

button.addChild(textLine);

}

button.addEventListener(MouseEvent.CLICK, presionado);

function presionado (e:MouseEvent):void{

  var webs:URLRequest = new URLRequest(e.target.url);

  navigateToURL(webs);

//buttonsContainer.addChild(button);

}

Quisiera que alguno de ustedes me pudiesen ayudar, he tratado de hacerlo por una semana y no se me ocurre nada, por favor.

espero su respuesta

PD. los links que aqui puse son ejemplos.

This topic has been closed for replies.
Correct answer kglad

there are several errors in your code/thinking.

you have a for-loop that does nothing.

button is defined as a sprite.

you use i outside that for-loop several times

you have an extraneous close-curly bracket - }

you try and use button as an array when adding a listener

your listener is calling presionado() but there is no such function

there is one function hold() but there is no listener to call that function and it does nothing.

you're trying to use a mouseevent (e) outside that function body so e will be undefined and so will e.target and e.target.url

try:

var nombresBotones:Array = new Array ("GOOGLE", "YAHOO", "HOTMAIL", "Password", 'CRISTALAB');

var direccionesWeb:Array = new Array ("","http://www.yahoo.com.mx","http://www.hotmail.com","http://www.intercambiosvirtuales.orghttp://www.google.com.mx","http://www.cristalab.com" ");

for (var i = 0; i < 5; i ++) {

var button:MovieClip = new MovieClip();

button.graphics.beginFill(0xff0066, 0.5);

button.graphics.drawRect (0, 0, 70, 25);

button.graphics.endFill ();

button.x = i * 80;

button.y = 30;

var str:String = nombresBotones ;

var fontDescription:FontDescription = new FontDescription ("Arial", "normal");

var format:ElementFormat = new ElementFormat(fontDescription, 14, 0x000000, 1);

var textElement:TextElement = new TextElement (str.toUpperCase (), format);

var textBlock:TextBlock = new TextBlock();

textBlock.content = textElement;

textBlock.baselineZero = TextBaseline.ROMAN;

var textLine: TextLine = textBlock.createTextLine(null, 300);

textLine.x = 5;

textLine.y = textLine. height+5;

button.buttonMode = true;

addChild (button);

button.addChild (textLine);

button.url = direccionesWeb;

button.addEventListener(MouseEvent.CLICK,hold);

}

function hold(e:MouseEvent):void{

navigateToURL(new URLRequest(e.currentTarget.url));

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 18, 2015

there are several errors in your code/thinking.

you have a for-loop that does nothing.

button is defined as a sprite.

you use i outside that for-loop several times

you have an extraneous close-curly bracket - }

you try and use button as an array when adding a listener

your listener is calling presionado() but there is no such function

there is one function hold() but there is no listener to call that function and it does nothing.

you're trying to use a mouseevent (e) outside that function body so e will be undefined and so will e.target and e.target.url

try:

var nombresBotones:Array = new Array ("GOOGLE", "YAHOO", "HOTMAIL", "Password", 'CRISTALAB');

var direccionesWeb:Array = new Array ("","http://www.yahoo.com.mx","http://www.hotmail.com","http://www.intercambiosvirtuales.orghttp://www.google.com.mx","http://www.cristalab.com" ");

for (var i = 0; i < 5; i ++) {

var button:MovieClip = new MovieClip();

button.graphics.beginFill(0xff0066, 0.5);

button.graphics.drawRect (0, 0, 70, 25);

button.graphics.endFill ();

button.x = i * 80;

button.y = 30;

var str:String = nombresBotones ;

var fontDescription:FontDescription = new FontDescription ("Arial", "normal");

var format:ElementFormat = new ElementFormat(fontDescription, 14, 0x000000, 1);

var textElement:TextElement = new TextElement (str.toUpperCase (), format);

var textBlock:TextBlock = new TextBlock();

textBlock.content = textElement;

textBlock.baselineZero = TextBaseline.ROMAN;

var textLine: TextLine = textBlock.createTextLine(null, 300);

textLine.x = 5;

textLine.y = textLine. height+5;

button.buttonMode = true;

addChild (button);

button.addChild (textLine);

button.url = direccionesWeb;

button.addEventListener(MouseEvent.CLICK,hold);

}

function hold(e:MouseEvent):void{

navigateToURL(new URLRequest(e.currentTarget.url));

}

Participant
March 18, 2015

Excelente, en verdad me he equivocado; muchas gracias por hacerme ver mi error, además gracias por tan rapida y acertada respuesta.

solo una pregunta mas, en Flash CC, me sale un error de migracion:

Esenea 1, Capa 1, Fotograma 1, linea 45, columna 8, Warning: 1058, Problema de migración, la propiedad url ya no se admite.

Alguna sugerencia?

kglad
Community Expert
Community Expert
March 19, 2015

you can ignore that warning, but i hate warnings so i would change url to something to eliminate the compiler's confusion:

button.urlS = direccionesWeb;

button.addEventListener(MouseEvent.CLICK,hold);

}

function hold(e:MouseEvent):void{

navigateToURL(new URLRequest(e.currentTarget.urlS));

}