Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Add close button to loader AS3

Hi all,

I am creating a loader (window) at runtime in AS3 but I need to add an X (close button) on the top-right corner.

Can anyone help please.

Please see code below.

Thanks

ST3VO

var myMapWindow:Sprite = new Sprite();
var myText:TextArea = new TextArea();
 
addChild(myMapWindow);
myMapWindow.addChild(myText);
myMapWindow.visible=false;
mapbtn.addEventListener(MouseEvent.CLICK, clickHandlermapbtn);
 
	function clickHandlermapbtn(eo:MouseEvent):void {
	myText.editable = false;
	myText.height = 480;
	myText.width = 645;
	myText.move(125,110);
	myText.setStyle("fontFamily", "Arial");
	myText.htmlText = "<b>Reference Number:</b> "+ nuTitle + "<br><br>" + 
	"<b>Description:</b> " + nuDescription + "<br><br>" +
	"<img src='_map/map1.jpg'><br><br>" +
	"<b>Location:</b> " + nuLocation + "<br><br>" + 
	"<b>PostCode:</b> " + nuPostcode + "<br><br>" + 
	"<b>Contact Location:</b> " + nuCompanyLocation;
	
 
 
myMapWindow.visible=true;
 
 
    
}

Open in new window

Avatar of scooby_56
scooby_56
Flag of United Kingdom of Great Britain and Northern Ireland image

try a function to removeChild or make invisible

var myMapWindow:Sprite = new Sprite();
var myText:TextArea = new TextArea();
 
addChild(myMapWindow);
myMapWindow.addChild(myText);
myMapWindow.visible=false;

mapbtn.addEventListener(MouseEvent.CLICK, clickHandlermapbtn);
function clickHandlermapbtn(eo:MouseEvent):void {
   myText.editable = false;
   myText.height = 480;
   myText.width = 645;
   myText.move(125,110);
   myText.setStyle("fontFamily", "Arial");
   myText.htmlText = "<b>Reference Number:</b> "+ nuTitle + "<br><br>" +
   "<b>Description:</b> " + nuDescription + "<br><br>" +
   "<img src='_map/map1.jpg'><br><br>" +
   "<b>Location:</b> " + nuLocation + "<br><br>" +
   "<b>PostCode:</b> " + nuPostcode + "<br><br>" +
   "<b>Contact Location:</b> " + nuCompanyLocation;
 
   //myMapWindow.visible=true;
  closeWin();    
}

function closeWin():void{ removeChild(myMapWindow) }
Avatar of ST3VO

ASKER

Sorry, you might have misunderstood me.

The loader creates a window and a textarea right now.
I need a close button created too.

Know what I'm trying to do?
ok...
so it looks like 'myMapWindow' is the container for the controls?

var btnClose:Sprite = new ButtonFromLibrary();
btnClose.addEventListener(MouseEvent.MOUSE_UP btnCloseHandler)
function btnCloseHandler(e:MouseEvent):void{
	trace(e.target + " clicked")
	removeChild(myMapWindow);// this may need to be removeChild(e.target.parent);
}
 
myMapWindow.addChild(btnClose);
myMapWindow.x = 200;
myMapWindow.y = 5;

Open in new window

Avatar of ST3VO

ASKER

Hmm...

I get errors on line 2


btnClose.addEventListener(MouseEvent.MOUSE_UP btnCloseHandler)

error is:

1084: Syntax error: expecting rightparen before btnCloseHandler.


//comma needed between MouseEvent.MOUSE_UP and  btnCloseHandler
btnClose.addEventListener(MouseEvent.MOUSE_UP, btnCloseHandler)
Avatar of ST3VO

ASKER

Another error:

1180: Call to a possibly undefined method ButtonFromLibrary.
sorry... i made an assumtion here,  i should have explained

You obviously need a graphical button so create something that looks like a close button, convert to symbol which adds to the library.

This example a Sprite exists in the library called 'ButtonFromLibrary'
Name yours what ever you like and change this code accordingly
ASKER CERTIFIED SOLUTION
Avatar of Eaddy Barnes
Eaddy Barnes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ST3VO

ASKER

I still have problems here:

I'm getting:

1151: A conflict exists with definition nuTitle in namespace internal.
1151: A conflict exists with definition nuDescription in namespace internal.
1151: A conflict exists with definition nuLocation in namespace internal.
1151: A conflict exists with definition nuPostcode in namespace internal.
1151: A conflict exists with definition nuCompanyLocation in namespace internal.

////////

Problems here:

////// vars in html code
var nuTitle:String = "nuTitle";
var nuDescription:String = "nuDescription";
var nuLocation:String = "nuLocation";
var nuPostcode:String = "nuPostcode";
var nuCompanyLocation:String = "nuCompanyLocation";
////// vars in html code

Avatar of ST3VO

ASKER

This code works (see attached code):

It just needs to close button added.

Thanks again

st3vo


import flash.display.Sprite;
import fl.controls.TextArea;*/
 
 
 
////////////////////////////////////////
/*var myMapWindow:Sprite = new Sprite();
var myText:TextArea = new TextArea();
 
addChild(myMapWindow);
myMapWindow.addChild(myText);
myMapWindow.visible=false;
mapbtn.addEventListener(MouseEvent.CLICK, clickHandlermapbtn);
 
function clickHandlermapbtn(eo:MouseEvent):void
{
        myText.editable = false;
        myText.height = 480;
        myText.width = 645;
        myText.move(125,110);
           //myText.setStyle("textFormat", myFormat);
        //myText.setTextFormat(myFormat);
//      myText.embedFonts = true;//test
        myText.setStyle("fontFamily", "Arial");
 
        var nuTitle:String = "nuTitle";
        var nuDescription:String = "nuDescription";
        var nuLocation:String = "nuLocation";
        var nuPostcode:String = "nuPostcode";
        var nuCompanyLocation:String = "nuCompanyLocation";
        
        myText.htmlText = "<b>Reference Number:</b> "+ nuTitle + "<br><br>" + 
                "<b>Description:</b> " + nuDescription + "<br><br>" +
                "<img src='_map/map1.jpg'><br><br>" +
                "<b>Location:</b> " + nuLocation + "<br><br>" + 
                "<b>PostCode:</b> " + nuPostcode + "<br><br>" + 
                "<b>Contact Location:</b> " + nuCompanyLocation;
 
        myMapWindow.visible=true;
}

Open in new window

Avatar of ST3VO

ASKER

Errors sorted Thanks :o)