开发者

How to use Flash content in a Java Micro Edition application?

开发者 https://www.devze.com 2023-03-05 19:03 出处:网络
Despite my luddite tendencies, I now have a phone with Java support - but no Flash support. I also have a copy of Macromedia Flash MX2004, though I\'m unlikely to upgrade any time soon.

Despite my luddite tendencies, I now have a phone with Java support - but no Flash support. I also have a copy of Macromedia Flash MX2004, though I'm unlikely to upgrade any time soon.

What I'd like to be able to do is develop some content (including vector animations) in Flash, then use those resources in a Java Micro Edition application. I don't need all features of Flash - in particular, I don't care about ActionScript support. But I do want to be able to load a SWF file (or, perhaps better, an alternative file format that can be generated using a converter tool), and to be able to display animations and use other resources (particularly play sounds) from in that file.

Is there a good library and toolkit to support this kind of thing? Obviously (from the MX2004) it doesn't need to be completely up to date.

On knowledge level - I've been a programmer for decades, and my everyday language these days is C++. However, I have a very limited knowledge of Java, and virtuall开发者_StackOverflow中文版y no knowledge (yet) of Micro Edition and its libraries.

I've already heard of Flash to J2ME converters, but so far as I can see they generate complete applications in one step, rather than treating the SWF file as a source of resources to be controlled from separately written Java code.

EDIT

I get the feeling that this is (with slight modifications) probably quite easy. Java Mobile Edition supports SVG vector graphics. SVG supports animations. There are (I'm pretty certain) ways to convert flash animations to SVG - probably a simple export-to-SVG in the application, though I've not checked.

This in itself doesn't give me a convenient bundle-of-media resources file format, but that's a relatively simple problem to solve, so long as there's a way to "load" SVG and other media files from some kind of non-file stream class that gets its data in turn from the bundle-of-media file.


I've never used Java ME before, so I won't be able to help on that side, but I use actionscript/flash on a daily basis.

The 'easiest' thing I can think of is a 2 step process:

  1. Export your animation as vector sequence via File > Export > Export Movie and choosing the right format (e.g. .ai/.eps/.dxf).
  2. Convert the vector sequence to svg. Inkscape has a few handy SVG conversion tools.

A long winded way would be to write a JSFL script in Flash MX 2004. You would traverse the shapes for each frame, then write the path data to SVG. Another slightly different way would be to export the vector sequence as explained above (unfortunately there is no JSFL functionality to automate that), then from JSFL read and loop through each file, parse it and write an SVG. The only advantage this would give you though is not having to install Inkscape and you wouldn't need to switch to another application. I wouldn't recommend this though because:

  1. You would need to write a parser (dxf/eps might be the simplest)
  2. You will need to make an SVG and you only have Strings at your disposal (E4X XML support was added in Flash CS3)

I'm not saying it's impossible, it just seems impractical.

Found this thread on the Inkscape forum sharing a bash script that

extracts SWF objects to an SVG file

using SWFTools, but haven't tried that yet. For reference, here is hadi's script:

#!/bin/bash

#USAGE ./swf2svg.sh /path/to/file.swf > output.svg

FILE=$1;
DUMP="dump.txt"

echo '<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg">

';

swfdump -s $FILE > $DUMP

fillCols=();
lineCols=();
lineWidth=();

FILLREGEX="[0-9]+(\s*)SOLID [0-f]{8}";
LINEREGEX="[0-9]+(\s*)[0-9]\.[0-9]{0,2} [0-f]{8}";

lastStartPoint="";
pathClosedTag="";
firstGroup="TRUE";
firstPath="TRUE";

cat $DUMP | while read line 
do
   #Remove ( and )
   line=`echo $line | sed "s/[()]//g"`

   #tmp=`echo $line | egrep -o "DEFINE(SHAPE|SPRITE)"`;
   tmp=`echo $line | egrep -o "DEFINE(SHAPE|SPRITE)[0-9]? defines id [0-9]+"`;

   if [ "$tmp" !=  "" ]
   then
      if [ "$firstGroup" == "TRUE" ]
      then
         firstGroup="FALSE";
      else
         if [ "$firstPath" == "FALSE" ]
         then
            if [ "$lastStartPoint" != "" ]
            then
               if [ "$lastStartPoint" == "$curPoint" ]
               then
                  pathClosedTag="Z";
               fi
            fi

            lastStartPoint=$curPoint;
            echo $pathClosedTag'" />';
         fi;
         firstPath="TRUE";
         echo '</g>';
      fi

      id=`echo $tmp | awk {'print $4'}`

      echo '<g id="'$id'">';
      fillCols=();
      lineCols=();
      lineWidth=();
   fi

   tmp=`echo $line | egrep -o  "($FILLREGEX)?((\s*)$LINEREGEX)?"`;
   if [ "$tmp" !=  "" ]
   then
      fillInx=`echo $tmp | egrep -o  "$FILLREGEX" | awk {'print $1'}`;
      fillCol=`echo $tmp | egrep -o  "$FILLREGEX" | awk {'print $3'}`;

      if [ "$fillCol" != "" ] 
      then
         fillCols[$fillInx]=$fillCol;
      fi

      lineInx=`echo $tmp | egrep -o  "$LINEREGEX" | awk {'print $1'}`;
      lineWth=`echo $tmp | egrep -o  "$LINEREGEX" | awk {'print $2'}`;
      lineCol=`echo $tmp | egrep -o  "$LINEREGEX" | awk {'print $3'}`;
      if [ "$lineCol" != "" ] 
      then
         lineCols[$lineInx]=$lineCol;
         lineWidth[$lineInx]=$lineWth;
      fi
   fi

   tmp=`echo $line | awk {'print $6'}`;

   if [ "$tmp" ==  "lineTo" ]
   then
      echo $line | awk {'print "L"$7" "$8'}
   fi

   if [ "$tmp" ==  "moveTo" ]
   then

      curPoint=`echo $line | awk {'print $9" "$10'}`;

      if [ "$lastStartPoint" != "" ]
      then
         if [ "$lastStartPoint" == "$curPoint" ]
         then
            pathClosedTag="Z";
         fi
      fi

      lastStartPoint=$curPoint;

      if [ "$firstPath" == "TRUE" ]
      then
         firstPath="FALSE";
      else
         echo $pathClosedTag'" />';
      fi;

      #Remove : and /
      line=`echo $line | sed "s/[:/]/ /g"`

      fInx=`echo $line | awk '{printf "%d", $4}'`;
      lInx=`echo $line | awk '{printf "%d", $6}'`;

      stl="";
      val=${fillCols[$fInx]:0:6};
      if [ $fInx -gt 0 -a "$val" != "" ]
      then
         stl="fill:#$val;";
      fi

      val=${lineCols[$lInx]:0:6};
      if [ $lInx -gt 0 -a "$val" != "" ]
      then
         stl=$stl"stroke:#$val;";

         val=${lineWidth[$lInx]};
         if [ "$val" != "" ]
         then
            stl=$stl"stroke-width:$val;";

         fi
      fi

      echo '<path style="'$stl'" d="';
      echo $line | awk {'print "M"$9" "$10'}
   fi

   if [ "$tmp" ==  "splineTo" ]
   then
      echo $line | awk {'print "Q"$7" "$8" "$9" "$10'}
   fi

done
echo 'Z" />';
echo '</g>';
echo '</svg>';

If anybody else using a more recent version of Flash (like CS4 or CS5) reads this, there is a Flash 2 SVG extension available.

0

精彩评论

暂无评论...
验证码 换一张
取 消