Archive for October, 2011

[AS3] When I load local movie file, security error has occured.

Sunday, October 23rd, 2011

I usually develop flash content with Flash Builder.

First I output the swc file from Flash CS 5 application.
And then, I import it from FB.
And I compile it to swf.

I tried to load the movie file in local file system.
But an Error dialog has been appeared.

The dialog said this.

SecurityError: Error #2148: SWF file file:///Users/kinkuma/Documents/temp/main.swf cannot access local resource ./video/samplef4v.f4v. Only local-with-filesystem and trusted local SWF files may access local resources.

I googled it. And I found how to solve it.
This page shows
Only local-with-filesystem and trusted local SWF files may access local resources

It says I have to add the compiler settings.
Project > Properties > ActionScript Compiler > Additional compiler arguments

-use-network=false

I can fix it!

Caution
If you load external swf files, you have to make all swf files same network policy.

Additional info
You can select the above settings with Flash Application.

File > Publish Settings > Local playback security

[jsx] Merge layers on Photoshop utility

Thursday, October 20th, 2011

I made a utility of Photoshop.
It is written in jsx(javascript file).

It makes each layer merge.
That means it remove layer’s filters and mask.

When I import designer’s photoshop data into Flash or Mobile project,
the filters and mask are not necessary.

Copy below text and paste into new file named merge.jsx(whatever you like).
And in Photoshop app,
Select menu
File > Scripts > Browse…
and select the file.
You must have seen the files without filters and masks.

Here is the code.

var doc = app.activeDocument;
mergeLayers(doc.layers);
alert('merge complete');

function mergeLayers(layers){
    var len = layers.length;
    var parent = layers.parent;
    var newLayer;
    for(var i = 0; i < len; i++){
        var layer = layers[i];
        if(layer.isBackgroundLayer){
            continue;
        }
        layer.allLocked = false;
        if(layer.typename == 'ArtLayer'){
            newLayer = parent.artLayers.add();
            newLayer.move(layer, ElementPlacement.PLACEAFTER);
            layer.merge();
        }
        else if(layer.typename == 'LayerSet'){
            mergeLayers(layer.layers);
        }
    }
}

[Android] Get RSS from network and parse it

Sunday, October 16th, 2011

I tried to get cnet.com RSS and parse it.

mainActivity.java

package com.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.os.Bundle;

public class HttpGetDemoActivity extends Activity {
	private ArrayList articles;
	private final String ITEM = "item";
	private final String TITLE = "title";
	private final String PUB_DATE = "pubDate";
	private final String GUID = "guid";
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        loadXML();
    }
    
    private void loadXML() {
        BufferedReader in = null;
        String xmlStr = "";
        try{
        	String url = "http://news.cnet.com/8300-1_3-1.xml?categoryId=1999&keywords=Gadget%20news";
        	HttpClient client = new DefaultHttpClient();
        	HttpGet request = new HttpGet(url);
        	HttpResponse responce = client.execute(request);
        	
        	in = new BufferedReader(new InputStreamReader(responce.getEntity().getContent()));
        	
        	StringBuffer sb = new StringBuffer("");
        	String line = "";
        	String NL = System.getProperty("line.separator");
        	while((line = in.readLine()) != null){
        		sb.append(line + NL);
        	}
        	in.close();
        	
        	xmlStr = sb.toString();
        	//System.out.println(page);
        	
        }catch(Exception e){
        	e.printStackTrace();
        }finally{
        	if(in != null){
        		try{
        			in.close();
        		}catch(IOException e){
        			e.printStackTrace();
        		}
        	}
        }
        
        try{
        	parseXML(xmlStr);
        }catch(IOException e){
        	e.printStackTrace();
        }catch(XmlPullParserException e){
        	e.printStackTrace();
        }
	}

	public void parseXML (String xmlStr) throws XmlPullParserException, IOException
    {
    	XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    	factory.setNamespaceAware(true);
    	XmlPullParser xpp = factory.newPullParser();
    	
    	xpp.setInput(new StringReader(xmlStr));
    	int eventType = xpp.getEventType();


    	Boolean isItem = false;
    	ArticleData articleData = null;
    	
    	while(eventType != XmlPullParser.END_DOCUMENT){
    		String xmlNodeName;
    		
    		switch(eventType){
    			case XmlPullParser.START_DOCUMENT:
    				articles = new ArrayList();
    				break;
    			case XmlPullParser.START_TAG:
    				xmlNodeName = xpp.getName();
    				if(xmlNodeName.equalsIgnoreCase(ITEM)){
    					isItem = true;
    					articleData = new ArticleData();
    				}
    				if(isItem){
        				if(xmlNodeName.equalsIgnoreCase(TITLE)){
        					articleData.title = xpp.nextText();
        				}else if(xmlNodeName.equalsIgnoreCase(PUB_DATE)){
        					articleData.pubDate = xpp.nextText();
        				}else if(xmlNodeName.equalsIgnoreCase(GUID)){
        					articleData.guid = xpp.nextText();
        				}
    				}
    				break;
    			case XmlPullParser.END_TAG:
    				xmlNodeName = xpp.getName();
    				if(xmlNodeName.equalsIgnoreCase(ITEM)){
    					isItem = false;
    					articles.add(articleData);
    				}
    				break;
    		}
    		
    		eventType = xpp.next();
    	}
    }
}

ArticleData.java

package com.demo;

public class ArticleData {
	String title;
	String pubDate;
	String guid;
}

XMLPullParseSample was from this site. Thank you!
>> Consuming A SOAP Web Service: XmlPullParser Alternative

[Android] Permit Internet access

Friday, October 14th, 2011

in AndroidManifest.xml


[Android] Failed to install app, timeout

Tuesday, October 11th, 2011

I got an error on debugging.
When I debugging, I can’t install my app.

The article on this link is the same error.
Android error: Failed to install *.apk on device *: timeout

And I could see how to fix it.

First, change the time of time out longer.

Preference > Android > DDMS
ADB connection time out (ms):
I changed default 5000 to 10000.

Second, reboot adb.

On the terminal app, I typed this code.

adb kill-server
adb start-server

I could fix it.