Getting lastLocation null using fusedlocationclient inside fragment - google-maps

I'm using fusedlocationclient to get the current user location, but somehow the lasLocation is null.
Here's my Location Fragment:
package com.example.atry.MakeComplaint
import Retrofit.INodeJS
import Retrofit.Observables
import Retrofit.RetrofitClient
import android.app.Activity
import android.content.ContentValues.TAG
import android.content.Context
import android.content.Context.*
import android.content.Intent
import android.content.IntentSender
import android.content.pm.PackageManager
import android.location.*
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.gms.maps.MapView
import android.widget.LinearLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getSystemService
import com.ashiqur.weatherapp.utils.GPSUtils
import com.example.atry.R
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.api.ResolvableApiException
import com.google.android.gms.dynamic.SupportFragmentWrapper
import com.google.android.gms.location.*
import com.google.android.gms.maps.*
import com.google.android.gms.maps.model.*
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.fragment_complaint_details.view.*
import kotlinx.android.synthetic.main.fragment_location.*
import kotlinx.android.synthetic.main.fragment_location.view.*
import retrofit2.Call
import retrofit2.Response
import java.io.IOException
import java.util.Observer
import java.util.Optional.empty
import java.util.jar.Manifest
import javax.security.auth.callback.Callback
class LocationFragment : Fragment(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener {
override fun onMarkerClick(p0: Marker?)= false
private lateinit var map: GoogleMap
private lateinit var mapView : MapView
lateinit var myAPI: INodeJS
var MyCategory: Observables.ComplaintType?=null
private var listener: OnLocationFragmentInteractionListener? = null
var objectComplaint =
Observables.Complaint(
1 , "dummy problem" ,
"url" ,
Observables.Location("99","99"),
Observables.ComplaintType("Smell", "null"),
Observables.Status(2 , "Unresolved")
)
//for updating user's location/ for current location
private lateinit var fusedLocationClient: FusedLocationProviderClient
private lateinit var locationRequest: LocationRequest
private lateinit var locationCallback: LocationCallback
private lateinit var lastLocation: Location
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val permissions = arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION)
requestPermissions( permissions,0)
getLocationUpdates()
//INIT API
val retrofit = RetrofitClient.instanc
myAPI = retrofit.create(INodeJS::class.java)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val v = inflater.inflate(com.example.atry.R.layout.fragment_location, container, false)
mapView = v.findViewById(R.id.maps)
mapView.onCreate(savedInstanceState)
mapView.onResume()
try {
MapsInitializer.initialize(getActivity()!!.getApplicationContext());
} catch (sendEx: IntentSender.SendIntentException) {
sendEx.printStackTrace();
}
mapView.getMapAsync(this)
v.backToList.setOnClickListener {
backFragment()
}
v.forwardToDescription.setOnClickListener{
getAllData()
}
return v
}
/**
* call this method in onCreate
* onLocationResult call when location is changed
*/
private fun getLocationUpdates() {
//with fusedLocationClient
fusedLocationClient = LocationServices.getFusedLocationProviderClient(context!!)
locationRequest = LocationRequest()
locationRequest.interval = 1000
locationRequest.fastestInterval = 5000
locationRequest.smallestDisplacement = 170f // 170 m = 0.1 mile
locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY //set according to your app function
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
locationResult ?: return
if (locationResult.locations.isNotEmpty()) {
// get latest location
lastLocation = locationResult.lastLocation
Log.d("lastlocation",lastLocation.toString())
// use your location object
// get latitude , longitude and other info from this
}
}
}
}
//Places the marker on the map and changes its style.
//start location updates
private fun startLocationUpdates() {
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,
null /* Looper */
)
}
// stop location updates
private fun stopLocationUpdates() {
fusedLocationClient.removeLocationUpdates(locationCallback)
}
// start receiving location update when activity visible/foreground
override fun onResume() {
super.onResume()
mapView.onResume()
startLocationUpdates()
}
// stop receiving location update when activity not visible/foreground
override fun onPause() {
super.onPause()
mapView.onPause()
stopLocationUpdates()
}
override fun onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
override public fun onLowMemory() {
super.onLowMemory();
mapView.onLowMemory()
}
override fun onMapReady(googleMap: GoogleMap?) {
map = googleMap!!
map.uiSettings?.isZoomControlsEnabled = true
map.isMyLocationEnabled = true
val marker = MarkerOptions().position(LatLng(lastLocation.latitude,lastLocation.longitude)).title("hello maps")
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
map.addMarker(marker)
val cameraPosition = CameraPosition.builder().target(LatLng(lastLocation.latitude,lastLocation.longitude)).zoom(12f).build()
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
private fun backFragment() {
val manager = (context as AppCompatActivity).supportFragmentManager
manager.popBackStackImmediate()
}
}
Also, if someone could just get this working by using location manager or something else I would really appreciate it. Or maybe a link or video where I could follow.

Related

Retrofit 2 - Getting response 200, but list is empty

I've tried to get some json from this api: https://api.cointelegraph.com/api/v1/mobile/feed
I want to get the "title" field of each news. I created the class that supposed to get this fields and wrapper for this class, but I'm getting an empty list instead of this, i guess it's because I have to get field, which called "data" firstly and then parse it. So I changed my class for getting "title" fields to class for getting "data" field, but I'm still getting empty list.
I guess it's kinda stupid mistake, because it works with github api. I will put some kind of response below and my code. Thanks for trying to help.
Json response:
{"data":{"news":[{"type":"header","data":{"id":22358,"title":"MIT, Stanford Researchers to Fund New \u2018Globally Scalable\u2019 Cryptocurrency, \u2018Unit-e\u2019","lead":"Major U.S. universities including MIT, Stanford and UC Berkeley have teamed up to fund a new digital currency.","thumb":"https://s3.cointelegraph.com/storage/uploads/view/f7a7d42a1cba645f861ba810d2524f77.jpg","published_at":{"date":"2019-01-17 18:52:00.000000","timezone_type":3,"timezone":"Europe/London"},"share_url":"https://cointelegraph.com/news/mit-stanford-researchers-to-fund-new-globally-scalable-cryptocurrency-unit-e","views":2375,"type":"news","author":"Helen Partz","author_id":545,"tag":"Blockchain","badge":{"title":"News","label":"default"},"isSponsored":false,"audio":"https://s3.cointelegraph.com/audio/22358.71732d08-dc28-4787-98b1-46c4e0317916.mp3"}},{"type":"currencies","data":[{"price":3677.37,"name":"BTC","currency":"USD","isIncreased":1,"difference":"0.89"},{"price":123.57,"name":"ETH","currency":"USD","isIncreased":1,"difference":"0.17"},{"price":31.56,"name":"LTC","currency":"USD","isIncreased":1,"difference":"0.19"},{"price":0.33,"name":"XRP","currency":"USD","isIncreased":1,"difference":"1.22"}]}
Interface:
package com.hfad.cointask.service
import com.hfad.cointask.model.DataLIst
import com.hfad.cointask.model.NewsList
import retrofit2.Call
import retrofit2.http.*
interface CoinClient {
#GET("api/v1/mobile/feed")
fun getFeed(): Call<NewsList>
}
News class:
package com.hfad.cointask.model
class News (private var data: String) {
fun getData(): String{
return data
}
}
I've tried to get title in first time like that
package com.hfad.cointask.model
class News (private var title: String) {
fun getTitle(): String{
return title
}
}
My wrapper for News class:
package com.hfad.cointask.model
class NewsList {
var list = mutableListOf<News>()
}
My adapter:
package com.hfad.cointask.adapter
import android.support.v7.view.menu.MenuView
import android.support.v7.view.menu.MenuView.ItemView
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.RecyclerView.ViewHolder
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.hfad.cointask.R
import com.hfad.cointask.model.News
class CoinAdapter(var values: List<News>): RecyclerView.Adapter<CoinAdapter.CoinViewHolder>() {
override fun onBindViewHolder(p0: CoinViewHolder, p1: Int) {
val itemTitle: News = values[p1]
p0.newsTitle.text = itemTitle.getData()
}
override fun getItemCount(): Int {
return values.size
}
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): CoinViewHolder {
val view: View = LayoutInflater.from(p0.context).inflate(R.layout.news_item_view, p0, false)
return CoinViewHolder(view)
}
class CoinViewHolder(itemView: View): ViewHolder(itemView) {
var newsTitle: TextView = itemView.findViewById(R.id.item_title)
}
}
And my main activity:
package com.hfad.cointask
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.widget.Toast
import com.hfad.cointask.adapter.CoinAdapter
import com.hfad.cointask.model.DataLIst
import com.hfad.cointask.model.News
import com.hfad.cointask.model.NewsList
import com.hfad.cointask.service.CoinClient
import kotlinx.android.synthetic.main.activity_feed.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class FeedActivity : AppCompatActivity() {
var news = mutableListOf<News>()
private lateinit var newsRecyclerView: RecyclerView
private lateinit var newsAdapter: CoinAdapter
private lateinit var layoutManager: LinearLayoutManager
private val client = mCoinClient().build()
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_home -> {
message.setText(R.string.title_home)
return#OnNavigationItemSelectedListener true
}
R.id.navigation_dashboard -> {
message.setText(R.string.title_dashboard)
return#OnNavigationItemSelectedListener true
}
R.id.navigation_notifications -> {
message.setText(R.string.title_notifications)
return#OnNavigationItemSelectedListener true
}
}
false
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_feed)
newsRecyclerView = findViewById(R.id.news_recycler_view)
layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
newsRecyclerView.layoutManager = layoutManager
newsAdapter = CoinAdapter(news)
newsRecyclerView.adapter = newsAdapter
getNews().enqueue(object: Callback<NewsList>{
override fun onResponse(call: Call<NewsList>, response: Response<NewsList>) {
var jsonNews = response.body().list
news.clear()
news.addAll(response.body().list)
newsAdapter.notifyDataSetChanged()
}
override fun onFailure(call: Call<NewsList>?, t: Throwable?) {
val toast = Toast.makeText(this#FeedActivity, t.toString(), Toast.LENGTH_SHORT)
toast.show()
}
})
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
}
private fun getNews() = client.getFeed()
class mCoinClient {
private val builder = Retrofit
.Builder()
.baseUrl("https://api.cointelegraph.com/")
.addConverterFactory(GsonConverterFactory.create())
private val retrofit: Retrofit by lazy {
builder.build()
}
private val client: CoinClient by lazy {
retrofit.create(CoinClient::class.java)
}
fun build() = client
}
}
Thanks for any help
I think it you should change your Interface to
interface CoinClient {
#GET("api/v1/mobile/feed")
fun getFeed(): Call<Your Object that you want to receive it with>
}

Is my code ineffecient or needing the garbage collector?

don't know if you're allowed to ask that here, but I wanted to know if my code is inefficient and leaves much work to the garbage collector, because I'm trying to find a source of lag in my game.
Heres the class, which loads the world through json files.
Worldloader.java:
package com.Sidescroll.game.Helpers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.Sidescroll.game.GameObjects.Background;
import com.Sidescroll.game.GameObjects.Platform;
import com.Sidescroll.game.GameObjects.Player;
import com.Sidescroll.game.GameWorld.GameWorld;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
public final class WorldLoader {
private WorldLoader() {}
public static HashMap<String, GameWorld> worlds = new HashMap<String, GameWorld>();
private static JsonValue jsonPlatforms, jsonSpawn, jsonBackgrounds;
public static GameWorld loadWorld(String levelName) {
if(worlds.get(levelName) != null) return worlds.get(levelName);
//load json file
FileHandle handle = Gdx.files.internal("levels/" + levelName + ".json");
String fileContent = handle.readString();
JsonValue json = new JsonReader().parse(fileContent);
jsonPlatforms = json.get("platforms");
jsonBackgrounds = json.get("backgrounds");
jsonSpawn = json.get("spawn");
//loads platforms
List<Platform> platforms = new ArrayList<Platform>();
for(JsonValue pValue : jsonPlatforms.iterator()) {
Platform platform = new Platform(pValue.getInt("x"),
pValue.getInt("y"),
pValue.getInt("width"),
pValue.getInt("height"),
Platform.Type.valueOf(Platform.Type.class, pValue.getString("type")),
pValue.getString("variant"));
platforms.add(platform);
}
//create player
Vector2 vecSpawn = new Vector2(jsonSpawn.getInt("x"), jsonSpawn.getInt("y"));
Player player = new Player(vecSpawn, platforms);
//loads backgrounds
List<Background> backgrounds = new ArrayList<Background>();
for(JsonValue bgValue : jsonBackgrounds.iterator()) {
Background bg = new Background("bin/sprites/" + bgValue.getString("name") + ".png",
bgValue.getInt("x"),
bgValue.getInt("y"),
bgValue.getInt("width"),
bgValue.getInt("height"),
bgValue.getBoolean("front"));
backgrounds.add(bg);
}
worlds.put(levelName, new GameWorld(player, platforms, backgrounds));
return worlds.get(levelName);
}
}

Starling cannot access a property or method of a null object reference

Hey any help appreciated i've been mind boggled by the asset manager for a couple of days
Here is my Hawaii class that I'm trying to reference assets from my asset manager class (MapAssetLoadQeue). and I'm getting the Cannot access a property or method of a null object reference. Error, the error is thrown in my Hawaii class if I don't (Null) the Asset Manager reference, and it is thrown in my Loader Class haw.showHawaii()
Thanks!!!
package Maps
{
import flash.filesystem.File;
import Enqueue.MapAssetLoadQeue;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.core.Starling;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;
public class Hawaii extends Sprite
{
public var mal:MapAssetLoadQeue = new MapAssetLoadQeue;
public var Ocean:Image;
public function Hawaii():void{
super();
this.addEventListener
(starling.events.Event.ADDED_TO_STAGE, showHawaii);
}
public function showHawaii(e:Event):void{
if(mal.mapAssets != null) {
Ocean = new Image(mal.mapAssets.getTexture("blue"));
addChild(Ocean);
Ocean.x = 0;
Ocean.y = 0;
}
}
Here is my loader class where I load my assets, and here is where I get my error. haw.showHawaii(null) function. Cannot access a property or method of a null object reference.
package Assets {
import flash.filesystem.File;
import Enqueue.MapAssetLoadQeue;
import GUI.Wave;
import Maps.Hawaii;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.core.Starling;
import starling.core.starling_internal;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;
public class Loader extends Sprite {
var loadText: Texture = Texture.fromEmbeddedAsset(loadMCTexture);
var loadXml: XML = XML(new loadMC0Xml());
var loaderAtlas: TextureAtlas = new TextureAtlas(loadText, loadXml);
public var loaderMovie: MovieClip = new MovieClip(loaderAtlas.getTextures("loading_"));
public var mal: MapAssetLoadQeue = new MapAssetLoadQeue;
public var wave:Wave = new Wave;
public var haw:Hawaii;
//Loader MovieClip size 720X233;
[Embed(source = "/../Wavehunter/loadScreenAssets/wm/MovieClips/loader/loader_0.xml", mimeType = "application/octet-stream")]
public static const loadMC0Xml: Class;
[Embed(source = "/../Wavehunter/loadScreenAssets/wm/MovieClips/loader/loader_0.png")]
public static const loadMCTexture: Class;
// public var juggler:Juggler = Starling.juggler;
/*
======================================================================
Every Movieclip asset for the worldMap
> Load WorldMap Assets on stage as Png and Make all alpha to 30%
> and within each function make that png invible to false or remove
> add MoviClip over the invisible png after load is processed
=======================================================================
*/
// Load WorldMap asset function
public function mapLoader(): void {
mal.requestWM();
addChild(loaderMovie);
loaderMovie.x = 347;
loaderMovie.y = 277;
loaderMovie.play();
Starling.juggler.add(loaderMovie);
}
public function mapLdr(){
loaderMovie.visible = true;
addChild(loaderMovie);
loaderMovie.x = 347;
loaderMovie.y = 277;
loaderMovie.play();
Starling.juggler.add(loaderMovie);
}
//this function resizes the loader to original size and places at the bottom corner
public function resizeLdr(){
loaderMovie.width = 72;
loaderMovie.height = 22;
loaderMovie.x =1237;
loaderMovie.y = 712;
}
public function callLoad(): void {
public function callHawaii(): void {
trace(" Hawaii is being runned");
//mal.mapAssets.verbose = true;
mal.mapAssets.loadQueue(function onGo(ratio: Number): void {
trace("Hawaii percentage is", ratio);
if (ratio == 1.0) {
Starling.juggler.delayCall(function (): void {
loaderMovie.visible = false;
//addChild(haw.Ocean);
// addChild(haw);
trace("this is haw value",haw);
//trace("this is the function", haw.showHawaii(null));
haw.showHawaii(null);
}, 0.30);
}
});
}
public function showMap() {
// get texture by name
addChild(mal);
mal.accesMap();
mal.hawaii.addEventListener(Event.TRIGGERED,removeMap);
}
// this code removes the HawaiiMap from the screen and goes directly to the wave
public function removeMap(){
trace("function initated");
mapLdr();
resizeLdr();
mal.mapAssets.purge();
mal.requestHawaii();
callHawaii();
mal.hawaii.removeEventListener(Event.TRIGGERED,removeMap);
}
public function Loader() {
super();
}
}
}
And here is my Asset Manager class
package Enqueue {
import flash.filesystem.File;
import Assets.MapAnimate;
import Assets.MapAssets;
import Maps.Hawaii;
import starling.animation.IAnimatable;
import starling.animation.Juggler;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.core.starling_internal;
import starling.display.Button;
import starling.display.Image;
import starling.display.MovieClip;
import starling.display.Sprite;
import starling.events.EnterFrameEvent;
import starling.events.Event;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import starling.utils.AssetManager;
public class MapAssetLoadQeue extends Sprite {
public var mapAssets: AssetManager;
public function MapAssetLoadQeue() {
super();
}
public function requestHawaii():void {
// mapAssets.verbose =false;
// mapAssets = new AssetManager;
var appDir:File = File.applicationDirectory;
mapAssets.enqueue(appDir.resolvePath("IslandMaps/Hawaii"));
//mapAssets.enqueue(Hawaii);
mapAssets.verbose = true;
}
If this is all of your code, and if I'm not missing something obvious, I don't see you creating "haw" anywhere. That is, you don't appear to have anything such as...
haw = new Hawaii();
...so, it would be null!

AS3: ReferenceError: Error #1069:

I'm trying to load a sound file into my Flash project. I keep getting this error however.
ReferenceError:
Error #1069: Property COMPLETE not found on flash.events.Event and there is no default value. at LoadSND/soundLoaded()[C:\Users\Admin\Desktop\Final Project\LoadSND.as:38]
The relevant code:
package {
import flash.events.*;
import flash.media.*;
import flash.net.URLRequest;
public class LoadSND {
//declare variables
private var sndTrack: Sound;
private var sndChannel: SoundChannel;
private var sndVolume: Number;
private var newTrack: String;
private var canRepeat: Boolean;
public function LoadSND(myTrack: String, myRepeat: Boolean = true) {
// constructor code
// set a default volume and track
sndVolume = 0.5;
setTrackData(myTrack, myRepeat);
}
private function loadSound(): void {
// first stop all old sounds playing
SoundMixer.stopAll();
// create a new sound for the track and a new sound channel
sndTrack = new Sound();
sndChannel = new SoundChannel();
// load the required sound
sndTrack.load(new URLRequest(newTrack));
// when loaded – play it;
sndTrack.addEventListener(Event.COMPLETE, soundLoaded);
}
private function soundLoaded(Event): void {
// finished with this listener so remove it
sndTrack.removeEventListener(Event.COMPLETE, soundLoaded);
// call the play sound function
playSound();
}
private function playSound(): void {
// assign music to the musicChannel and play it
sndChannel = sndTrack.play();
// setting the volume control property to the sound channel
sndChannel.soundTransform = new SoundTransform(sndVolume, 0);
// but add this one to make repeats
sndChannel.addEventListener(Event.SOUND_COMPLETE, playAgain);
}
private function playAgain(Event): void {
// remove this listener and repeat playSound()
sndChannel.removeEventListener(Event.SOUND_COMPLETE, playAgain);
playSound();
}
private function setTrackData(myTrack: String, myRepeat: Boolean): void {
// update the new track information
newTrack = myTrack;
canRepeat = myRepeat;
// and load it
loadSound();
}
private function setVolumeLevel(Number): void {
}
} //end class
} //end package
Loading a default track through my Main.as
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.utils.Dictionary;
import flash.text.TextFormat;
import flash.net.*;
import flash.events.*;
import fl.controls.*;
import flash.media.*;
import fl.events.ComponentEvent;
import fl.managers.StyleManager;
import fl.data.DataProvider;
import fl.data.SimpleCollectionItem;
import fl.managers.StyleManager;
import fl.events.ComponentEvent;
import flash.events.Event;
import flash.net.SharedObject;
import LoadSWF;
import GameButton;
import LoadSND;
public class Main extends MovieClip {
//Sound Variables
private var MAX_TRAX: int = 7;
private var MAX_SFX: int = 9;
private var sndPath: String;
private var sndTrack: LoadSND;
private var isMuted: Boolean;
private var canRepeat: Boolean;
private var sndVolume: Number;
public function Main() {
// constructor code
sndPath = "musicSFX/Fury.mp3";
isMuted = false;
sndTrack = new LoadSND(sndPath, canRepeat);
}
Any help is appreciated :) Thanks
The problem lies in the definition of soundLoaded function. You put just class in there instead of argument with type declaration. It should be solved if you adjust definition of the soundLoaded function in the following way:
private function soundLoaded(event:Event): void
By the way same problem is in functions playAgain and setVolumeLevel.

Actionscript mobile Madcomponents Mapquest

i am trying to add map in action script mobile app i have created xml for the layout, as the tags for the xml layout are predefined so i believe we cannot create custom tags, so i added that map using image tag but now the trouble is the mad components has disabled its scroll as well, no regrets that was suppose to be happen because i have created map under image, i tried to put the scrollVertical as well but that didn't work because that map was under image tag.
below is my code.
package
{
import com.danielfreeman.madcomponents.*;
import com.mapquest.*;
import com.mapquest.services.geocode.*;
import com.mapquest.tilemap.*;
import com.mapquest.tilemap.controls.inputdevice.*;
import com.mapquest.tilemap.controls.shadymeadow.*;
import com.mapquest.tilemap.pois.*;
import flash.display.Screen;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.system.Capabilities;
import flash.text.TextField;
import flash.utils.flash_proxy;
import mx.events.FlexEvent;
public class map extends Sprite
{
private static var alResults:Array;
static var myMap:TileMap = new TileMap("my Key");
static var geocoder:Geocoder;
public static const LAYOUT:XML = <scrollVertical background="#DADED4" >
<imageLoader id="placeholder"> </imageLoader >
</scrollVertical>;
protected static var _message:UILabel;
public static function initialize():void{
var placeholder:UIImageLoader = UIImageLoader(UI.findViewById("placeholder"));
placeholder.scrollRect
placeholder.addChild(myMap);
myMap.addControl(new SMLargeZoomControl());
myMap.addControl(new SMViewControl());
myMap.addControl(new MouseWheelZoomControl());
myMap.size = new Size(300, 400);
myMap.addControl(new SMLargeZoomControl());
myMap.addControl(new SMViewControl());
myMap.addControl(new MouseWheelZoomControl());
// create a new TileMap object, passing your platform key
geocoder = new Geocoder(myMap);
geocoder.addEventListener(GeocoderEvent.GEOCODE_RESPONSE, onGeocodeResponse);
geocoder.addEventListener(GeocoderEvent.GEOCODE_ERROR_EVENT, onGeocodeError);
geocoder.addEventListener(GeocoderEvent.HTTP_ERROR_EVENT, onHttpError);
doGeocode();
}
public function map()
{
super();
}
private static function onGeocodeResponse(e:GeocoderEvent):void {
alResults = new Array();
for each (var loc:GeocoderLocation in e.geocoderResponse.locations) {
var o:Object = new Object();
o.LatLng = loc.displayLatLng.lat + ", " + loc.displayLatLng.lng;
o.GeocodeQuality = loc.geocodeQuality;
o.GeocodeQualityCode = loc.geocodeQualityCode;
alResults.push(o);
}
//this.dgResults.dataProvider = this.alResults;
//this.vgrpResults.visible = true;
}
private static function doGeocode():void {
//remove all shapes form the map
myMap.removeShapes();
//use the default cursor
//this.cursorManager.setBusyCursor();
//make an array to hold the addresses
var arrAddresses:Array = new Array();
//push the addresses onto the array
arrAddresses.push("placea");
arrAddresses.push("place b");
//call the geocoder object's geocode method, passing the array of addresses
geocoder.geocode(arrAddresses);
}
private static function onGeocodeError(e:GeocoderEvent):void {
//this.cursorManager.removeBusyCursor();
makeErrorList("GEOCODER ERROR");
}
/*
function to handle an error in the result
*/
private static function onHttpError(e:GeocoderEvent):void {
//this.cursorManager.removeBusyCursor();
makeErrorList("HTTP ERROR");
}
/*
function to make an array list to hold an error
*/
private static function makeErrorList(s:String):void {
var o:Object = new Object();
o.LatLng = s;
alResults.push(o);
//this.dgResults.dataProvider = this.alResults;
//this.vgrpResults.visible = true;
}
}
}
has any one got any idea how do i achieve my goal :S
help will be really appreciated.
Instead of using vertical i have used scrollXY than search for scroll see the following code
package
{
import com.danielfreeman.extendedMadness.UIScrollXY;
import com.danielfreeman.madcomponents.*;
import com.mapquest.*;
import com.mapquest.services.geocode.*;
import com.mapquest.tilemap.*;
import com.mapquest.tilemap.controls.inputdevice.*;
import com.mapquest.tilemap.controls.shadymeadow.*;
import com.mapquest.tilemap.pois.*;
import flash.display.Screen;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.system.Capabilities;
import flash.text.TextField;
import flash.utils.flash_proxy;
import mx.events.FlexEvent;
public class map extends Sprite
{
private static var alResults:Array;
static var myMap:TileMap = new TileMap("My Key");
static var geocoder:Geocoder;
public static const LAYOUT:XML =
<scrollXY tapToScale="3.0" stageColour="#666666" scrollBarColour="#FFFFFF" width="480" height="640" border="false" id="scroller">
<imageLoader id="placeholder"> </imageLoader >
</scrollXY>;
protected static var _message:UILabel;
public static function initialize():void{
var scroller:UIScrollXY = UIScrollXY(UI.findViewById("scroller"));
scroller.addChild(myMap);
/*var placeholder:UIImageLoader = UIImageLoader(UI.findViewById("placeholder"));
placeholder.scrollRect
placeholder.addChild(myMap);
*/ myMap.addControl(new SMLargeZoomControl());
myMap.addControl(new SMViewControl());
myMap.addControl(new MouseWheelZoomControl());
myMap.size = new Size(300, 400);
myMap.addControl(new SMLargeZoomControl());
myMap.addControl(new SMViewControl());
myMap.addControl(new MouseWheelZoomControl());
// create a new TileMap object, passing your platform key
geocoder = new Geocoder(myMap);
geocoder.addEventListener(GeocoderEvent.GEOCODE_RESPONSE, onGeocodeResponse);
geocoder.addEventListener(GeocoderEvent.GEOCODE_ERROR_EVENT, onGeocodeError);
geocoder.addEventListener(GeocoderEvent.HTTP_ERROR_EVENT, onHttpError);
doGeocode();
}
public function map()
{
super();
}
private static function onGeocodeResponse(e:GeocoderEvent):void {
alResults = new Array();
for each (var loc:GeocoderLocation in e.geocoderResponse.locations) {
var o:Object = new Object();
o.LatLng = loc.displayLatLng.lat + ", " + loc.displayLatLng.lng;
o.GeocodeQuality = loc.geocodeQuality;
o.GeocodeQualityCode = loc.geocodeQualityCode;
alResults.push(o);
}
//this.dgResults.dataProvider = this.alResults;
//this.vgrpResults.visible = true;
}
private static function doGeocode():void {
//remove all shapes form the map
myMap.removeShapes();
//use the default cursor
//this.cursorManager.setBusyCursor();
//make an array to hold the addresses
var arrAddresses:Array = new Array();
//push the addresses onto the array
arrAddresses.push("Loc1");
arrAddresses.push("Loc2");
//call the geocoder object's geocode method, passing the array of addresses
geocoder.geocode(arrAddresses);
}
private static function onGeocodeError(e:GeocoderEvent):void {
//this.cursorManager.removeBusyCursor();
makeErrorList("GEOCODER ERROR");
}
/*
function to handle an error in the result
*/
private static function onHttpError(e:GeocoderEvent):void {
//this.cursorManager.removeBusyCursor();
makeErrorList("HTTP ERROR");
}
/*
function to make an array list to hold an error
*/
private static function makeErrorList(s:String):void {
var o:Object = new Object();
o.LatLng = s;
alResults.push(o);
//this.dgResults.dataProvider = this.alResults;
//this.vgrpResults.visible = true;
}
}
}