I've integrate a map from MapQuest in my Adobe Air app (in AS3).
The map is taking all the screen as I want.
BUT, I'd like to add a "back" button in order to go back to the previous menu.
Here's my code :
var NoumeaNord:TileMap = new TileMap("KEYcode");
//set the size of the map
NoumeaNord.size = new Size(800, 533);
//add the map to the sprite.
addChild(NoumeaNord);
NoumeaNord.addControl(new SMLargeZoomControl());
NoumeaNord.addControl(new MouseWheelZoomControl());
NoumeaNord.addShape(new Poi(new LatLng(-22.2758000,166.4580000)));
NoumeaNord.setCenter(new LatLng(-22.2758000,166.4580000),15);
function addBackBtn():void{
var back:MovieClip;
back = new backBtn
addChild(back);
back.x = 0;
back.y = 400;
setChildIndex(back,0);
}
Don't know why but the BackBtn won't be in front of the map !
I've tried with setChildIndex(back,-1); but it makes an error : "RangeError: Error #2006: index is off limit".
Any idea ?
In this situation I use holders like this:
private var bgHolder:Sprite;
private var contentHolder:Sprite;
private var menuHolder:Sprite;
Somewhere in the constructor I run a method that will set my holders. For example:
function setHolders()
{
bgHolder = new Sprite();
addChild(bgHolder);
contentHolder = new Sprite();
addChild(contentHolder);
menuHolder = new Sprite();
addChild(menuHolder);
}
Then I just add my content to the desired holder in any order between destination holder and I can always be sure to add my content to the correct "layer";
So just add your back button to the menuHolder:
menuHolder.addChild(back);
And don't worry about adding it below the map or out of index, because the map, in this case, would be added to the contentHolder!
Hope that helps!
that's because you add your back button first
just make sure that you first add the map then add the button
Related
Presently, I am attempting to add the ability to capture all the slides of a presentation to images and save them to disk. It works now where the first page is capture, then I want an async event to fire when the second page has loaded to capture that page, and so on. Here is where I have added an event listener, though I'm not sure if I should be using stage or this:
import flash.events.Event;
private var jpgEncoder:JPGEncoder;
// ...
private function init():void{
// ...
// Add async event to capture second page after loading
stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
// ...
}
private function onPrintButtonClicked():void {
// screen capture code
jpgEncoder = new JPGEncoder(90);
// Page 1 capture
bitmapData1 = new BitmapData(stage.width, stage.height);
bitmapData1.draw(stage, new Matrix());
// move to next page
var curPage:Page = PresentationModel.getInstance().getCurrentPage();
if (curPage != null) {
LOGGER.debug("Go to next page. Current page [{0}]", [curPage.id]);
pageCount++;
dispatchEvent(new GoToNextPageCommand(curPage.id));
} else {
LOGGER.debug("Go to next page. CanNOT find current page.");
}
}
private function onLoadComplete(e:Event)
{
// Get page 2 capture
bitmapData2 = new BitmapData(stage.width, stage.height);
bitmapData2.draw(stage, new Matrix());
// Copy two pages to one bitmap
var rect1:Rectangle = new Rectangle(0, 0, stage.width, stage.height);
var pt1:Point = new Point(0, 0);
bitmapData3 = new BitmapData(stage.width, stage.height * 2);
bitmapData3.copyPixels(bitmapData1, rect1, pt1)
var rect2:Rectangle = new Rectangle(0, 0, stage.width, stage.height);
var pt2:Point = new Point(0, stage.height);
bitmapData3.copyPixels(bitmapData2, rect2, pt2)
// Convert to image
var img:ByteArray = jpgEncoder.encode(bitmapData3);
var file:FileReference = new FileReference();
file.save(img, "capture1.jpg");
}
Does anyone have any ideas as to why the OnLoadComplete function is never called? FYI, here is the full source code: https://github.com/john1726/bigbluebutton/blob/master/bigbluebutton-client/src/org/bigbluebutton/main/views/MainToolbar.mxml
TIA
Please note that I've found that the stage was still null in the init() method so an exception was being thrown:
stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
Also, after resolving that stage error I found that I have been receiving this error using this tool: https://github.com/capilkey/Vizzy-Flash-Tracer
Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.
So the solution is either to re-work the UI so that there is a button press to prepare the files and a second button press to actually save the image or setup them mouseup and mousedown events to call different functions:
s:Button mouseDown="prepare_PDF()" mouseUp="save_PDF()"
Source: Flex's FileReference.save() can only be called in a user event handler -- how can I get around this?
Thank you!
I have a preload movie that loads an interface. In the interface I have many buttons. When I click on a button I want to load a text file into a movie called "TextMovie.swf". I want to be able to click on a button, take the name of the button and load a text file that is the same name as the button instance, and have the window appear close to the mouse click. There will be hundreds of buttons and hundreds of text files. I'm sure this is easy for some. Here is the loader for a button:
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPosition_2);
function fl_ClickToPosition_2(event:MouseEvent):void
{
var my2ndLoader:Loader = new Loader();
var url2:URLRequest = new URLRequest("TextMovie.swf");
my2ndLoader.load(url2);
addChild(my2ndLoader);
my2ndLoader.x = 200;
my2ndLoader.y = 10;
}
Then in the TextMovie.swf I have:
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.StyleSheet;
var css:StyleSheet = new StyleSheet();
css.setStyle("a:hover", {textDecoration:"underline"});
var textLoader: URLLoader = new URLLoader();
textLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
textLoader.addEventListener(Event.COMPLETE, textLoaded);
loadText();
function textLoaded(evt: Event): void {
title_txt.htmlText = textLoader.data.txtTitle;
main_txt.htmlText = textLoader.data.txtBody;
URL_txt.htmlText = textLoader.data.txtURL;
URL_txt.styleSheet = css
}
function loadText(): void {
// var fileName: String = "assets/test_01.txt";
var fileName: String = "assets/" + + ".txt";
textLoader.load(new URLRequest(fileName));
}
I'm not sure how to get the name of the button I pushed and apply it to the string that will load the correct text file. I also can't get the window to appear close to the mouse click. Right now I just have it set with an x and y for testing.
I know it's a lot but thanks for any help.
I suggest you take a look at the docs for MouseEvent so you better understand what data is passed as parameters when the event is triggered.
In the event handler, a reference is passed to the object which was clicked: the event target– and from that you can get its name, location, etc. This is good because it means you only need one event handler for all your buttons.
Once you have the name, you can build the string you need for your url. (I wouldn't do it that way if it is a project which is going to have any sort of lifespan but it's an ok approach).
You can get the x and y location of the target, its width and height, and use that data to position your window. The localX and localY properties refer to the click location relative to the rect of the target (button) – with top/left of the target== 0,0.
This is the trace output from the function below:
red red.swf
600 400
25 8.5
button_1.addEventListener(MouseEvent.CLICK, onHandleButtonClick);
function onHandleButtonClick(event:MouseEvent):void
{
var btnName:String = event.target.name;
var swfName:String = btnName + ".swf";
trace(btnName, swfName);
trace(event.target.x, event.target.y);
trace(event.localX, event.localY);
}
I'm working in a project for basketball. I have an issue, all my code works great if all my components are in the main timeline.
But as soon as I convert the text fields into a movie clip so I can animate and apply alpha value, all stops working.
what am I doing wrong ? The only solution that I could think of is writing the result of my countdown into the text field in the movie clip, but it didn't work as well.
this is my code.
function onTimer ( ev:TimerEvent ) : void {
timeRemaining--;
if (timeRemaining < 0) {
timeRemaining = 0;
loseGame();
}
else
showTime.text = formatTimeRemaining ();
var miReloj:MovieClip;
var titulo_txt:TextField = new TextField();
titulo_txt.text = formatTimeRemaining ();
addChild(miReloj);
miReloj.addChild(titulo_txt);
// miReloj.addChild(showTime1.text);
//miReloj.showTime1.text = formatTimeRemaining ();
}
There's never a value being assigned to miReloj, that's why it's null
var miReloj:MovieClip; // no assignment here
var titulo_txt:TextField = new TextField();
titulo_txt.text = formatTimeRemaining ();
addChild(miReloj); // miReloj is still null here
miReloj.addChild(titulo_txt); // cannot call method on null
But as soon as I convert the text fields into a movie clip
That's impossible. From your code it looks like what you actually want to do is to add the TextField object to a container. There's no need to use a MovieClip for that, simply create a Sprite object:
var container:Sprite = new Sprite(); // create container
var title:TextField = new TextField();
title.text = formatTimeRemaining();
addChild(container); // add container
container.addChild(title); // add title to container
Always use English for all your programming. Don't mix other languages into it. It becomes a pain to read your code and decreases the number of people that can help you if you have problems with your code.
So first off i'd like to state that i am not very good at AS3, i'm completely self taught so i am sure that there are many things i've done badly, inefficiently or plain wrong and i'm happy for any comments on these if there is things i can improve.
Okay so, this seems like a really simple problem but i don't know the exact code for it and i can't find an example anywhere
what i want to do is to change the image which i am using for my character to a separate image on a button click, then after a certain amount of time for him to go back to the original.
My image is set as a movie clip and i am calling it like so :
public var Smallclock_hero = new Smallclock;
it is worth noting that smallclock has it's own separate class.
is there a way that i can change this image on a mouse click event ?
A simple way would be:
Add a new image on the second frame of the Smallclock movieclip. Have this new image span several frames of the timeline for the duration you want it to appear for.
Place a stop(); action on the first frame of the Smallclock movieclip.
btn.addEventListener(MouseEvent.CLICK, btnChangeCharacterFrame);
function btnChangeCharacterFrame(e:MouseEvent)
{
Smallclock_hero.gotoAndPlay(2);
// Or use a frame label
// Smallclock_hero.gotoAndPlay("jump");
}
This can be achieved relatively simply using the visible property and setTimeout. When you click on your MovieClip you'll want to make the old image invisible and the new image visible:
oldImage.visible = false;
newImage.visible = true;
Then you'll want to use setTimeout to change the visible properties back to:
oldImage.visible = true;
newImage.visible = false;
setTimeout can run a function after a specified number of milliseconds. Here is an example of this technique on wonderfl : http://wonderfl.net/c/acxl
private var imageA:ImageA = new ImageA();
private var imageB:ImageB = new ImageB();
private var revertId:int;
public function Main() {
imageB.visible = false;
addChild(imageA);
addChild(imageB);
addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void{
clearTimeout(revertId);
revertId = setTimeout(revert, 1000);
imageB.visible = true;
imageA.visible = false;
}
private function revert():void{
imageB.visible = false;
imageA.visible = true;
}
I'm trying to load images from google maps static images api into flash. When I attempt to load them flash complain about sandbox issues. Even after I try and load the policy file from google.
Security.loadPolicyFile("http://maps.googleapis.com/crossdomain.xml");
Is there any way around this? or is it simply impossible to load images in this fashion?
var loader1:Loader = new Loader();
var lctx1:LoaderContext = new LoaderContext(true);
loader1.contentLoaderInfo.addEventListener(Event.INIT, doImgInit);
loader1.load(new URLRequest("http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=600x400&maptype=satellite&sensor=false&scale=4"), lctx1);
private function doImgInit(evt:Event):void
{
trace("DO IT")
// get a reference to the LoaderInfo object in which the image is loaded
var lInfo:LoaderInfo = evt.target as LoaderInfo;
// this variable is used as reference to the image in the end.
var dO:DisplayObject;
// try to access the "content" property of the loader, if it works, there is a crossdomain.xml file.
try{
dO = lInfo.loader.content;
}
// if there wasn't one, we need to put the loader inside another object in order to manipulate it
catch(err:SecurityError)
{
// create a new Sprite to contain the loaded image
var sprt:Sprite = new Sprite();
// add the loader to the sprite
sprt.addChild(lInfo.loader);
// get a reference to this sprite in the dO variable
var dO:DisplayObject = sprt as DisplayObject;
}
// from here on you can do anything to the dO variable, rotate it, draw it unto a bitmapData, move it around..
// but first don't forget to add to to some container that is on the stage so you can see it!
}