I am try to make an application for android. I have 2 .xml file. which dynamically created after installing app as per user requirement. I used to save file path is File.applicationStorageDirectory.resolvedPath.
But for 1 file it works not for 2nd one. Its throwing error. even 2 more static xml also not loading if i used path 2 times for dynamic xml. Plz help me out
Thanks in Advance
Rachita
FOR LOADING XML
var file1:File = File.applicationStorageDirectory.resolvePath("myFav.xml");
var fileStream1:FileStream = new FileStream();
fileStream1.open(file1, FileMode.READ);
var imageList1:XML = XML(fileStream1.readUTFBytes(fileStream1.bytesAvailable));
fileStream1.close();
FOR SAVING XML
function saveXML(myXML:XML):void
{
var file2:File = File.applicationStorageDirectory.nnativePath("myFav.xml");
fileStream1.open(file2, FileMode.WRITE);
fileStream1.writeUTFBytes(myXML.toXMLString());
fileStream1.close();
}
Above mention is my code. it works for xml but the same if i am using for the second xml it throwing error #30003 file or directory does not exists.
So just plz check it out once.
Thanks in Advance.
In that code you're re-using a FileStream. You may have better luck re-creating your fileStream object every time. After you finish writing null out the file1/2 and the fileStream so the next time it fires off these fresh objects are re-created. Therefore you can't get into any "file is in use therefore you can't overwrite it" bugs.
But I did the same for 1st xml file name is "theme.xml". It works properly. When i run my code theme.xml saved in my local storage and i can change it through the application bt at the same time second xml have not save in my local storage.. I did the which you mentioned above. iused seprate file stream for all bt its not working...
Yes I see you're using the same FileStream object to manage both files and that's where I think the most appropriate place to adjust is.
There's a big difference between the two things you're doing. One is opening a file for FileMode.READ. The other is FileMode.WRITE. You're getting a security fileWriteResource error. That tells me either the FileStream being re-used might not work well with Android or you really don't have access to writing to the filesystem.
In your Android manifest XML file did you request permission to write to storage? Here's a picture of the relevant section taken from this adobe page:
You need to make sure you gave yourself this permission (uncomment it out if it is commented):
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Otherwise you are not allowed to write files.
If you have that permission and you're creating a new FileStream object as you should be, are you getting a different error?
Yes I agreed that There are two thing read and write a xml but i am reading the and writing both xml.. it is not like that one xml is static and one is dynamic. whole code are same for read and write.
so i ould save only one. second xml created when i run the code bt it is blank and i give static path for second xml it works . Bt i cant do that.. it should be saved in by default local path ....
I could not getting, what is the wrong with the code. I cross checked 100 of times
As long as you have write permission then I see nothing immediate wrong. You keep mentioning XML. XML is just text, regardless. This Adobe article on opening/editing/saving text using the FileStream class should give you plenty of insight on every part of the process:
http://www.adobe.com/devnet/air/flash/quickstart/articles/building_tex t_editor.html
Make sure you're checking IOErrorEvents for more information on your issues of course.
Hey Sorry to disturb you again. Actually i stuck with one more problem.
I used TransformGestureEvent for both zoom and pan. See i have one image that i can zoom. i maintain the aspect ratio also while zooming, i can pan also but while i am moving the object, it moves easily so that if i move bottom it can be move till top and layer under that image become visible that's i dont want. Even i restricted zoom out can't be less from 1028 X 750.this is my stage size so image it should maintain the axis - x between the 0-1280 and y-0-750.
Plz help.
Thanks in advance.
I'm not really sure what your question is. What it seems to be is your gestures are allowing your content to be sized outside your desired dimensions.
All I can tell you is you should always be multiplying via the value returned by the gesture event and then run the values the scale would result in though your own set of tests. If it's larger, smaller or in a position you don't want you simply ignore the event. That's always how I've kept my content in check and where I want it.
Hey Sinious, Yes i figured out.Thanks alot. but the thing is that how can i get value of touchpointid.
On one fingure touch i want touch and drag and two fingure touch or pinch i want zoom.
we cant merge multitouchgesture and multitouchpoint as per forum, so every time i have to remove and add event listener depending on touch type.
so what to do?
Thanks
How I do it is handle dragging myself manually using a standard MouseEvent. On MOUSE_DOWN I start either pay attention to MOUSE_MOVE or startDrag(rect) on the clip and handle a drag in that manner. That's how you'd always do it before in Flash so a single Touch for something Flash itself has always supported is probably why they don't work together.
I use MOUSE_MOVE more than startDrag as you can do more sophisticated things, albeit it can be expensive so keep the calculations as simple as possible. An example of a random MOUSE_DOWN handler setup that only moves horizontal (X axis):
// hold current position in lightweight ints (whole pixels only)
var startX:int;
// weak reference listener
someObj.addEventListener(MouseEvent.MOUSE_DOWN, _handleMouseDown, false, 0, true);
function _handleMouseDown(e:Event):void
{
// on initial MOUSE_DOWN, store starting value
startX = stage.mouseX;
// add MOUSE_MOVE and removal handler for movement
stage.addEventListener(MouseEvent.MOUSE_MOVE, _handleMouseMove);
stage.addEventListener(MouseEvent.MOUSE_UP, _handleRemoveMouseMove);
}
function _handleMouseMove(e:MouseEvent):void
{
// calculate
var delta:int = int(e.localX - startX);
// validate value, allow to go left -2000px and up to 0px
if ((someObj.x - delta) > -2000)
{
someObj.x -= delta;
startX = e.localX;
}
else if ((someObj.x - delta) >= 0)
{
someObj.x = 0;
startX = e.localX;
}
}
function handleRemoveMouseMove(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, _handleMouseMove);
stage.removeEventListener(MouseEvent.MOUSE_UP, _handleRemoveMouseMove);
// code here once drag is complete, check position? do something?
}
I typed it quick so there could be a logic issue in there but there's a random handler that should allow an object to go left up to -2000px and it uses standard MouseEvent. I apply listeners for MOUSE_MOVE and MOUSE_UP to the stage to assure if the users finger gets off the object that's moving they will still stop listening. Customize as necessary but this is ultimately Flash's age old built in drag/move code.
You could also calculate a valid Rect and use startDrag() to let Flash itself handle moving the object. I often want to do more things based on the position of the drag so I like to use a loop that keeps track of the position.
Yes i did the same only i used TOUCH_BEGIN, TOUCH_END. I m applying this on an image. so while once i zoom image after that i can drag or move the image. But if immediately if want to zoom more in that case zoom gesture does not work. even i used MOUSE_UP and MOUSE_DOWN also. That's why i have to count touchpointid. and One more thing i defined all Touch_BEGIN and TOUCH_END event and function in Zoom Function itself to get the value of zooming size.
If you're using MouseEvent to drag the object as shown above then you should be free and clear to use the zoom gesture to handle zooming. The zoom gesture returns a simple scale property you'd use to resize the image. You would't be using TOUCH_BEGIN/TOUCH_END at all.
The MouseEvent pan code would need to take the scale into consideration for its pan calculations of course.
Thanks Sinious. My basic issue has been resolved for zoom with drag..
Only one thing is remaining that once i zoom an image and dragged after that if i again zoom out little bit the image background image seen automatically which i dont want, actully immediately width and height is not been set..
There's an event that fires off when the zooming occurs for the gesture. You're hand-calculating the zoom based on the scale factor returned in the event. You're also going to be responsible for validating and correcting the x/y position of the image at the same time. So in the function that handles scaling the image during zoom, just validate the position and adjust as necessary to keep the background image from showing through.
I read somewhere that in android 4.0 or later version on movie clip Touch event will not work
see here :
http://sree.cc/corona-sdk/limiting-touch-events-to-the-masked-portion- of-the-object
http://cometkorea.tistory.com/156
One more thing is there any option to scale everything according to device size.
Because of their counter-parts (MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, CLICK) is why I would assume the touch events are removed. There's only one good reason for touch events, multiple touch points. Gestures can handle those for you however. I do little in the way of Android development at the moment but I've done multiple touch points in the past.
Scaling works the same way as it does in flash, just setting the stage.scaleMode to EXACT_FIT (no aspect ratio considerd) or NO_BORDER (aspect ratio retained). The content will "stretch" to the device size. Vectors look fine during this but bitmaps often take a hit. There's no magic bullet for this. You really should read the available device space and make a dynamic interface rather than scaling.
Game makers hate this and often just go with scaling. In this situation they typically make wide apps. They make sure the left and right side of their apps are "optionally seen" so on wide devices you see a bit more. As other devices narrow the edges are simply cropped off and unseen. It's a common game tactic but it requires you strictly keeping the vital controls and visuals inside a save margin.
There's so much in this thread would you mind opening a new thread and posting the relevant code so we don't need to read through it all? I think all you want to do is animate properties (position, alpha, etc) of images when changing and if so just use a Flash Tween or another more optimized library like TweenLite to handle animating those properties for you. Then you just specify the object you want to affect as well as which properties and values to change to and it will handle the animation (like move or fade in or out smoothly).
What you're saying is you want to see one exiting at the same time another is entering. So both on the screen at the same time. In that case you'll need to modify your timeline so they both exist at the same time. There's no way around that. It's not like powerpoint where you can choose a transition between frames.
North America
Europe, Middle East and Africa
Asia Pacific