issue with sharedobject in actionscript3 - ios

So I am trying to store and load data but for somereason I get error code 1046 - type was not found or was not a comile-time constant and 1120 - access of undefined property SharedObject.
I have imported the right files needed.
This code is in a frame on a timeline and should run once the person clicks on the page that is corresponding with the code.
Code:
import flash.desktop.NativeApplication;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.setInterval;
// Listen for exiting event.
NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);
// Also save every 30 seconds.
setInterval(save, 30*1000);
// Load data.
load();
function onExit(e:Event):void
{
save();
}
function save():void
{
// Get the shared object.
var so:SharedObject = SharedObject.getLocal("myApp");
// Update the age variable.
so.data['age'] = int(so.data['age']) + 1;
// And flush our changes.
so.flush();
// Also, indicate the value for debugging.
trace("Saved generation " + so.data['age']);
}
function load():void
{
// Get the shared object.
var so:SharedObject = SharedObject.getLocal("myApp");
// And indicate the value for debugging.
trace("Loaded generation " + so.data['age']);
}

As usual, this error means you haven't imported the class definition. Add this to the import section of your AS file:
import flash.net.SharedObject;

Related

how to require multiple files to a component within a react native app

I am trying to require multiple images from a folder within my react native project. I am trying to dynamically load the images I need to render an animation with a react-native-image-sequence component in another react component. I know you can only require images by only passing a string in react-native like this: require("../somepath"), so I am trying to find a work around to load multiple images by passing in a dynamic path. I need to be able to pass the image sequence component an array like this:
[ require("./1.png"),
require("./2.png"),
require("./3.png")
]
for it to render the animation sequence.
I have tried creating a file that contains a method called prepareDirImages that creates and returns a string that contains an array full of require statements to the path passed in as well as the extension of the file. My plan was to then use this method in the component that I am creating and calling eval(prepareDirImages("./dirPath", "png")) to transform the string into its actual array representation and then passing this into the image sequence component.
prepareReactImages.js:
module.exports = {
prepareDirImages(path, ext){
fs.readDir(path).then(files => {
const ex =
"[\n" +
files.map((x, index) =>{
if(index < result.length - 1){
return `require("${path}/${x}"),`
}
`require("${path}/${x}")`
}).join("\n") +
"]";
console.log(ex)
fs.writeFile("../images/index.js", ex);
return ex;
})
}
}
myComponent.js:
import React, { Component } from 'react';
import ImageSequence from 'react-native-image-sequence';
import { prepareDirImages } from '../services/prepareReactImages';
import { View, Text } from 'react-native';
const fs = require('react-native-fs');
export default class myComponent extends Component {
render(){
console.log(eval(prepareDirImages("../images/imagesDir", "png")))
let images = getImages();
return (
<View>
<ImageSequence
images={images}
style={this.props.style}
framesPerSecond={24}
/>
</View>
);
}
}
async function getImages(){
return eval(await prepareDirImages("../images/ed_anim_wave_v01",
"png"))
}
What I get is a promise and I get an error saying that imagesequence cant using property filter of object. I read that you have to use fs.MainBundlePath or fs.DocumentDirectoryPath but I dont understand how to get these files. If anyone can help me out, I'd appreciate it tremendously!!

Error Targeting Instance name from document class AS3

I have a document class with this function on it, it targets a symbol with an instance name of scene4_headlights on the stage:
function accUpdate(e:AccelerometerEvent):void{
scene4_headlights.rotation += (e.accelerationX*10);
}
But I keep getting error 1120: Access of undefined property scene4_headlights even though I have a symbol on the stage with the instance name of scene4_headlights..
Help?
Here you go:
package {
import flash.sensors.Accelerometer;
import flash.events.AccelerometerEvent; //importing everything you need is cruicial
import flash.display.MovieClip;
public class CustomClassName extends MovieClip //your custom class can extend the type of class you used to create your scene4_headlights instance (some prefer using Sprite when the timeline is not required)
{
private var accelerometer = new Accelerometer(); //declare a variable data type: Accelerometer
public function CustomClassName() {
// constructor code
accelerometer.addEventListener(AccelerometerEvent.UPDATE, accUpdate); // add an eventlistener to the variable you just created
}
public function accUpdate(e:AccelerometerEvent): void //declare the function handling the eventlistener
{
scene4_headlights.rotation += (e.accelerationX*10);
trace("The function accUpdate is linked properly"); //trace is your friend
}
}
}

Why long delay (47 secs) to go from camera to AIR on iPad2/iOS6 - CameraUI, Loader, MediaEvent, MediaPromise

I've had a great deal of success using the DevGirl XpenseIt solution offered by Jason Sturges in response to a couple of other requests for help with this: (http://stackoverflow.com/questions/11812807/take-photo-using-adobe-builder-flex-for-ios being the best example)
Great success except that between the time you press the 'Use' button in iOS6 after taking a photo using the CameraUI and the util class from the tutorial, it takes fully 47 1-hippopotamus, 2 hippapotamusses until the 'fileReady' event occurs.
It doesn't seem, to my mind that it should take the Loader class that terribly long.
Is there something I can do to improve this performance? I'm forced to add a hurry-up-and-wait UI element so my users won't think the program has hung. Here's the code of the CameraUtil.as from the above as I'm currently using it.
// http://stackoverflow.com/questions/11812807/take-photo-using-adobe-builder-flex-for-ios
package classes
{
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.MediaEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.media.CameraRoll;
import flash.media.CameraUI;
import flash.media.MediaPromise;
import flash.media.MediaType;
import flash.utils.ByteArray;
import mx.graphics.codec.JPEGEncoder;
import events.CameraEvent;
[Event(name = "fileReady", type = "events.CameraEvent")]
public class CameraUtil extends EventDispatcher
{
protected var camera:CameraUI;
protected var loader:Loader;
public var file:File;
public function CameraUtil(target:IEventDispatcher=null)
{
super(target);
if (CameraUI.isSupported)
{
camera = new CameraUI();
camera.addEventListener(MediaEvent.COMPLETE, mediaEventComplete);
}
} // End CONSTRUCTOR CameraUtil
public function takePicture():void
{
if (camera)
camera.launch(MediaType.IMAGE);
} // End FUNCTION takePicture
protected function mediaEventComplete(event:MediaEvent):void
{
var mediaPromise:MediaPromise = event.data;
if (mediaPromise.file == null)
{
// For iOS we need to load with a Loader first
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleted);
loader.loadFilePromise(mediaPromise);
return;
}
else
{
// Android we can just dispatch the event that it's complete
file = new File(mediaPromise.file.url);
dispatchEvent(new CameraEvent(CameraEvent.FILE_READY, file));
}
} // End FUNCTION mediaEventComplete
protected function loaderCompleted(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
if (CameraRoll.supportsAddBitmapData)
{
var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height);
bitmapData.draw(loaderInfo.loader);
file = File.applicationStorageDirectory.resolvePath("receipt" + new Date().time + ".jpg");
var stream:FileStream = new FileStream()
stream.open(file, FileMode.WRITE);
var j:JPEGEncoder = new JPEGEncoder();
var bytes:ByteArray = j.encode(bitmapData);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();
dispatchEvent(new CameraEvent(CameraEvent.FILE_READY, file));
}
} // End FUNCTION loaderComplete
} // End CLASS CameraUtil
} // End PACKAGE classes
I was able to solve my delay problem by removing a step from the process. This step is one I myself do not need (at the present time) but others may, so removing it is not really an answer to the question of 'why does this process that seems reasonable take what seems an unreasonable amount of time.
I needed the BitmapData, not an external file so instead of:
Camera => [snap] => Media Promise => Loader => Write File => Event => Read File => Use BitmapData
I rewrote the class to cut out the File/AppStorage i/o.
Camera => [snap] => Media Promise => Loader => Use BitmapData
and so a very reasonable (and expected amount of comp time).
I am still surprised however that it takes such a long time to write the data to a file using the method used in the CameraUtil class. I do need to write these images out to files, but not until the user has reduced the size to a 1024x768 crop area and I encode them into a very compressed jpg, so hopefully I'll only struggle with a smaller portion of the hang/comp time.
Anybody know... Should it take so very long to write 1 file to application storage in iOS from Adobe AIR (via flex)?
I found this process painstakingly slow, too ...
However, it seems the JPEGEncoder is contributing a lot to this delay.
You can speed up the process a lot using the optimized Encoder that can be found here.
http://www.bytearray.org/?p=775
Depending on your device it is about 2 to 4 times faster than the original one.
Another step that can be omitted is the bitmapData.draw(), which is slow as well, by using the Loader.content directly. This way you skip the instantiation of another bitmap instance, which will blowup memory usage.
Like this:
protected function loaderCompleted(event:Event):void
{
var loader:Loader = (event.target as LoaderInfo).loader;
var bitmap:Bitmap = loader.content as Bitmap;
(...)
}
Still, I'm waiting for somebody to write an iOS .ane which should be able to encode a jpg in a few ms instead of seconds. But in the meantime... ;)

Closing the child no errors but sub movie wont close

Hi i have looked up a lot of answers but havnt been able to fix my problem. I am using external actionscript and i have used the following code:
package
{
import flash.display.MovieClip;
import flash.net.*;
import flash.events.*;
import flash.display.Loader;
import fl.motion.MotionEvent;
import flash.ui.Mouse;
public class submenu1 extends MovieClip
{
private var movieLoader:Loader;
//everything in this function is exicuted when you start the application
public function submenu1()
{
movieLoader = new Loader();
image3_btn.addEventListener(MouseEvent.MOUSE_DOWN,addMovie);
image4_btn.addEventListener(MouseEvent.MOUSE_DOWN,addMovie);
exit_btn.addEventListener(MouseEvent.MOUSE_DOWN,closeTheMovie);
}
private function addMovie(e:MouseEvent)
{
if(e.target.name=="image3_btn")
{
loadTheMovie("image3");
}
else if(e.target.name=="image4_btn")
{
loadTheMovie("image4");
}
}
private function loadTheMovie(m:String)
{
var movieRequest:URLRequest = new URLRequest("../swf/" + m + ".swf");
movieLoader.load(movieRequest);
addChild(movieLoader);
}
private function closeTheMovie (e:MouseEvent)
{
removeChild(movieLoader);
exit_btn.addEventListener(MouseEvent.MOUSE_DOWN,closeTheMovie);
}
}
}
I can get the sub movie to open but i cant get the exit_btn to close the sub movie and return to the original. I am wanting the exit_btn when clicked to remove the child and take you back to the texture page. The flash itself doesn't bring up any errors just the button wont work. Any suggestions?
Did you export to actions script your exit buttons? Right click on the exit button then choose properties and then click on the box called export for actionScript.

ActionScript 3.0 CurrentLabel not working on Loaded .SWF file

I am trying to get this to work for ages but doesnt seem to work out quite well
this is my code:
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var cola:Loader;
cola = new Loader()
cola.load(new URLRequest("resources/colabar.swf"));
this.addChild(cola);
//cola.currentLabel = "frame1";
This works. The .swf is in my stage now. Moving from frame to frame.
Obiously, when deleting the // its not working. And ill get this error message: 1119: Access of possibly undefined property currentLabel through a reference with static type flash.display:Loader.
Try this:
cola.contentLoaderInfo.addEventListener(Event.COMPLETE, colaCompleteHandler);
...
function colaCompleteHandler(event:Event):void
{
var loader:Loader = LoaderInfo(event.target).loader;
var mc:MovieClip = loader.content as MovieClip;
if (mc) {
mc.gotoAndPlay("frame1");
}
}
i.e. wait for the SWF to load, then set the label.

Resources