Can't move variables outside of a function - actionscript-3

function playvideo(path:String, wid:Number=1280, heigt:Number=720):void
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
SoundMixer.stopAll();
var vid:Video = new Video();
ns.play(path);
vid.width = wid;
vid.height = heigt;
vid.attachNetStream(ns);
mc_bg.removeChildAt(0);
mc_bg.addChild(vid);
}
Greetings, here's my "playvideo" function. whenever I try to move variables outside of function to control the video from elsewhere(for example "vid"), specific movieclips and buttons dissapear(are not shown on the stage). Is that some kind of a bug or am I doing something wrong? Thanks!

do this:
var vid:Video = new Video();
function playvideo(path:String, wid:Number=1280, heigt:Number=720):void
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
SoundMixer.stopAll();
ns.play(path);
vid.width = wid;
vid.height = heigt;
vid.attachNetStream(ns);
mc_bg.removeChildAt(0);
mc_bg.addChild(vid);
}
And same for any var, declare outside function

Related

How send parameters for URLRequest

I have send parameters for my backend in PHP but i have code and i not send parameters look
var request:URLRequest = new URLRequest(modelLocator.CaminhoServidor+"AnexoDocumentos_Financeiro/asdas/xml.php");
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = Remessa;
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, RecebeXML);
loader.load(request);
how send 3 parameters this code?
You need to use the 'variables' field in the URLRequest object:
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.param1 = ...
variables.param2 = ...
variables.param3 = ...
request.data = variables;
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, urlLoader_error);
urlLoader.load(request);
Also, it's a good idea to define handlers for errors (as shown for IO_ERROR above but also HTTP_STATUS and SECURITY_ERROR)

google maps onclick go to marker on map

I'm having issues trying to get my map to go to the marker of a location when a "View on Map" link is clicked. I keep getting the error "TypeError: map.setOptions is not a function".
Here's the code:
var infowindow = null;
function initialize(){
var myOptions = {
zoom:3,
center:new google.maps.LatLng(0,0),
mapTypeId:google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(
document.getElementById('map'),myOptions);
setMarkers(map,sites);
}
var infowindow = new google.maps.InfoWindow({
content:'Loading...'
});
var sites = [
['GIC Campers Sydney',-33.935477,151.012108,1,'xxx'],
['GIC Campers Brisbane',-27.5445735,153.0139405,1,'yyy'],
['GIC Campers Melbourne',-37.650735,144.940551,1,'zzz']
];
function setMarkers(map,markers){
var bounds = new google.maps.LatLngBounds();
var image = new google.maps.MarkerImage('/templates/home/images/google-pin.png',
new google.maps.Size(60,60),
new google.maps.Point(0,0),
new google.maps.Point(30,60));
for(var i=0;i<markers.length;i++){
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1],sites[2]);
var marker = new google.maps.Marker({
position:siteLatLng,
map:map,
icon:image,
title:sites[0],
zIndex:sites[3],
html:sites[4]
});
google.maps.event.addListener(marker,'click',function(){
map.setZoom(15);
map.setCenter(marker.getPosition());
infowindow.setContent(this.html);
infowindow.open(map,this);
});
bounds.extend(siteLatLng);
map.fitBounds(bounds);
}
};
function loadcity(which){
initialize();
if(which == 'gic-campers-sydney'){
var newPos = new google.maps.LatLng(-33.935477,151.012108);
map.setOptions({center:newPos,zoom:15});
}
if(which == 'gic-campers-brisbane'){
var newPos = new google.maps.LatLng(-27.5445735,153.0139405);
map.setOptions({center:newPos,zoom:15});
}
if(which == 'gic-campers-melbourne'){
var newPos = new google.maps.LatLng(-37.650735,144.940551);
map.setOptions({center:newPos,zoom:15});
}
}
jQuery(document).ready(function(e) {
initialize();
jQuery('.updatemap').click(function(e){
e.preventDefault();
});
});
and an example link:
<a onclick="loadcity('gic-campers-brisbane');" class="updatemap" href="#gic-campers-brisbane">View on map</a>
Any help on this would be greatly appreciated.
Your map variable is local to the initialize function. It is not available inside the loadcity function.
One fix is to make it global (like your infowindow):
var infowindow = null;
var map = null;
function initialize(){
var myOptions = {
zoom:3,
center:new google.maps.LatLng(0,0),
mapTypeId:google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(
document.getElementById('map'),myOptions);
setMarkers(map,sites);
}
Not sure why you recreate the map (call initialize() every time loadcity runs), you really should only need to do that once.

AS3 - Is there an equivalent decode() to BitmapData.encode()?

Is there a way to turn the ByteArray back into a BitmapData after using BitmapData.encode()?
No, there isn't. You have to use Loader to load encoded JPEG and access bitmap data through the loaded content:
var bitmap:Bitmap = new Bitmap(new BitmapData(100, 100, false, 0xFF0000));
addChild(bitmap);
var bytes:ByteArray = new ByteArray();
bitmap.bitmapData.encode(bitmap.bitmapData.rect, new JPEGEncoderOptions(), bytes);
bitmap.bitmapData.dispose();
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void
{
var bd:BitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
bitmap.bitmapData = bd;
});
loader.loadBytes(bytes);

Google Maps marker do not appear on print

I am using Google Maps API V3 for showing Google map. I created a custom control for printing the map. But when I'm printing it the marker is not in that print out. Can anyone tell me how do I print the map along with the marker ? Thanks in Advance.
EDIT
Code to create the map
function map_start(el,id){
$lat = $("#"+id).attr("lat");
$lang = $("#"+id).attr("long");
var image = "../assets/paleblue_MarkerU.png";
var myOptions = {
center: new google.maps.LatLng($lat,$lang),
zoom: 12,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$map = new google.maps.Map(document.getElementById('inset'),myOptions);
var placeMarker = new google.maps.Marker({
position: new google.maps.LatLng($lat,$lang),
map: $map,
animation: google.maps.Animation.DROP,
icon: image
});
var homeControlDiv = document.createElement('div');
var homeControl = new HomeControl(homeControlDiv, $map);
homeControlDiv.index = 1;
$map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
}
Code for custom control to print the map
function HomeControl(controlDiv, map) {
controlDiv.style.padding = '5px';
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = 'white';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '2px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to print the map';
controlDiv.appendChild(controlUI);
var controlText = document.createElement('div');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.fontSize = '12px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.className = "gmnoprint";
controlText.innerHTML = '<b>Print</b>';
controlUI.appendChild(controlText);
google.maps.event.addDomListener(controlUI, 'click', function() {
printDiv('cboxContent')
});
}
Code for printing the map
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
window.location.reload();
}

Plot multiple points on google map using API

I am trying to show different points on any route on google map using the API. I want to pass in starting, stopping and finishing locations. Is this possible using the javascript API or would I need to look into other options such as geolocation?
I am using the following code to achieve this:
function initialize() {
var mapOptions = {
zoom: 10,
center: new google.maps.(-64.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=52554&sensor=false&callback=initialize";
document.body.appendChild(script);
}
Here is my code.
`<script type="text/javascript">
var geocoder = null;
var arr = new Array();
var arr1 = new Array();
var arr2 = new Array();
var map = null;
var chr;
var baseIcon = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng('<%=Request["Lat"]%>', '<%=Request["Long"]%>'), 13);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
baseIcon = new GIcon();
// baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(25, 30);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
// Creates a marker whose info window displays the letter corresponding to the given index.
function createMarker(point, index) {
// Create a lettered icon for this point using our icon class
var letter = String.fromCharCode("A".charCodeAt(0) + index);
var letteredIcon = new GIcon(baseIcon);
letteredIcon.image = "markers/marker" + index + ".png";
// Set up our GMarkerOptions object
markerOptions = { icon: letteredIcon };
var marker = new GMarker(point, markerOptions);
GEvent.addListener(marker, "click", function () {
marker.openInfoWindowHtml("<table><tr><td><img src=markers/marker" + index + ".png length=25 width=25 /></td>" + "<td>" + arr2[index] + "</td></tr></table>");
});
return marker;
}
for (var i = 0; i < arr.length; i++) {
var latlng = new GLatLng(arr[i], arr1[i]);
map.addOverlay(createMarker(latlng, i));
}
}
}
`