Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6113195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:49:52+00:00 2026-05-23T14:49:52+00:00

How to import json file in action script and then get random element from

  • 0

How to import json file in action script and then get random element from json array/object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:49:52+00:00Added an answer on May 23, 2026 at 2:49 pm

    I’m using as3corelib for parsing JSON. You can download it here:
    https://github.com/mikechambers/as3corelib

    I wrapped it to class:

    import com.adobe.serialization.json.JSON;
    
    import flash.events.EventDispatcher;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    
    public class JSONLoader extends EventDispatcher 
    {
    
        private var loader:URLLoader = new URLLoader() ;
        private var request:URLRequest = new URLRequest();
        public var jsonDecoded:Object = new Object();
    
        public function JSONLoader(DataURL:String):void
        {
    
            var JSONString:String = DataURL;
            //trace("JSONLoader - JSONString = "+JSONString);
    
            var urlRequest:URLRequest = new URLRequest(JSONString);
    
            //var urlLoader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, decodeJSON);
            loader.addEventListener(IOErrorEvent.IO_ERROR, urlLoadErrorHandler);
            loader.load(urlRequest);
    
            loader.addEventListener(Event.COMPLETE, decodeJSON) ;
    
        }
    
        public function decodeJSON(event:Event):void
        {               
            trace("JSONLoader - Jason - "+event.target.data);
    
            jsonDecoded = JSON.decode(event.target.data);       
            dispatchEvent (new Event("dataReady"));     
    
            removeListeners();
        }
    
        public function urlLoadErrorHandler(event:IOErrorEvent):void
        {
            trace("Jason - unable to load data");
            dispatchEvent (new Event("dataFailed"));
            removeListeners();
        }
    
        public function removeListeners():void
        {
            loader.removeEventListener(Event.COMPLETE, decodeJSON) ;
            loader.removeEventListener(IOErrorEvent.IO_ERROR, urlLoadErrorHandler);         
        }
    
        public function returnJsonDecoded():Object
        {
            trace("Jason jsonDecoded - "+jsonDecoded);
            return jsonDecoded;
        }   
    
    }
    

    Then call it like this:

    public function getData():void{
            var _URLpath:String = "localdata.json";
            jsonLoader = new JSONLoader(_URLpath);
            jsonLoader.addEventListener("dataReady", collectJSONData);
            jsonLoader.addEventListener("dataFailed", doJSONFailed);
        }
    private function collectJSONData(evt:Event):void
        {
            jsonObject = jsonLoader.returnJsonDecoded();
    }
    

    Then you have jsonObject and you can use like array and randomly pick up items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to import data from a JSON file into R? More
I m using tableview to populate an array from json file...In my view Controller
I have this very basic problem, >>> from django.core import serializers >>> serializers.serialize(json, {'a':1})
I took this script from here : import csv from itertools import izip f
How can I iterate through the following json file and if fa=cc.ee then add
I have been struggeling all day to read a json file from server and
import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when
import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[])
I have this JSON in a file: { "maps": [ { "id": "blabla", "iscategorical":
Is there a difference between importing something (e.g. #import JSON.h ) into the header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.