GeoTools: How to build a point? (imports issue) - gis

I'm following the GeoTools documentation and found this:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
Coordinate coord = new Coordinate(45, 15);
Point point = geometryFactory.createPoint(coord);
When I put it in intellij IDE, for each class there are several suggested imports to use. What import I need to select?
Alternative way (with same issue) is:
GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
Point point = builder.createPoint(45, 15);

When in doubt you can always read the documentation, for example JTSFactoryFinder returns a com.vividsolutions.jts.geom.GeometryFactory, once you know that the other pieces fall into place as:
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
Meanwhile your GeometryBuilder is an org.geotools.geometry.GeometryBuilder which leads to the following imports:
import org.geotools.geometry.GeometryBuilder;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.geometry.primitive.Point;

Related

How do I allow user to select tint amount in Flash Professional using ActionScript 3?

So I was in the middle of making a type of test program where I would take parts of a shirt and the user could customize it with different colors.
While I was doing that I realized it wasn't realistic as there was absolutely no fade with the color picker tool (code shown below).
Is there any way to allow the user to use possibly a slider to change the level of tint on the color(s) being used on the shirt?
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
import flash.geom.ColorTransform;
var mycolor:ColorTransform = new ColorTransform();
cp.addEventListener(ColorPickerEvent.CHANGE,colorChanger);
function colorChanger(event:ColorPickerEvent):void{
mycolor.color = cp.selectedColor;
mc2.transform.colorTransform = mycolor;
}
import fl.events.SliderEvent;
import fl.controls.Slider;
var slider:Slider=new Slider();
slider.maximum=100;
slider.value=100;
addChild(slider);
slider.addEventListener(SliderEvent.THUMB_DRAG,changeAlpha);
function changeAlpha(event:SliderEvent):void{
mycolor.alphaMultiplier=slider.value/100;
mc2.transform.colorTransform = mycolor;
}
Check this: flashandmath.com/howtos/tint
Very useful site, not only for tint! It's a big shame the authors don't really update it anymore. (but they still love flash, which is cool :o) )
You only need to use mc2.alpha = slider.value/100 to change it.

Making my character talk with a speechbubble using 2 actionscript3 (info below)

I've been taking a computer programming class for high school and I've been stuck on this problem for longer than I'd like to admit. I'm in a program that basically sets it up so you work at your own pace with a teacher and no classmates that know what I'm doing so basically I'm teaching myself to some extent.
Okay so my job is to make a speech bubble I made pop up when I click on my character using the script I made for my character (Shippo.as) and the speech bubble made this activity for assignment 1 (SpeechBubble.as).
So far when I run the program my character pops up, but when I click on him nothing happens. I get no errors or anything so the problem is with the code but I'm unable to spot it. I will display the codes for everything below by the names I'm using for them to hand in.
- U1A6As2 - Talking Character
import Shippo;
import SpeechBubble;
var shippo_mc:Shippo = new Shippo;
addChild(shippo_mc);
shippo_mc.x = 250;
shippo_mc.y = 200;
(this code creates and displays my character named Shippo.)
- SpeechBubble.as
package
{
import flash.display.MovieClip;
import mc_SpeechBubble;
import Shippo;
public class SpeechBubble extends MovieClip
{
public function SpeechBubble (xPosition:Number, yPosition:Number, message:String)
{
var bubble_mc:MovieClip = new mc_SpeechBubble();
bubble_mc.x = xPosition;
bubble_mc.y = yPosition;
bubble_mc.speechText_txt.text = message;
addChild(bubble_mc);
}
}
}
(This code is from the tutorial from Activity 6, Assignment 1, the only thing I added was import Shippo;)
- Shippo.as
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import mc_SpeechBubble;
import SpeechBubble;
public class Shippo extends MovieClip
{
public function Shippo()
{
trace ("Click me and I'll talk.");
this.addEventListener(MouseEvent.CLICK, shippoTalk);
}
public function shippoTalk(event:MouseEvent):void
{
var bubble:SpeechBubble = new SpeechBubble(350,50,"Hello, my
name's Shippo.");
addChild(bubble);
this.removeEventListener(MouseEvent.CLICK, shippoTalk);
}
}
}
(The only reason the trace ("Click me and I'll talk."); is in the code is just so I know that part is working correctly, it's not needed. I think the problem lies in the shippoTalk function but not sure how to fix it because the code in shippoTalk is the one used during assignment 1 of activity 6.)
Keep in mind I'm no flash pro and I don't know the language to well so bear with me, I'm trying to stick with what I have learned and not go to far off the rails but in all honesty as long as this gets done I will be happy, any help will be good help.
You've mis-spelled 'function' as 'funtion' in your mc_SpeechBubble constructor method.
Also f.y.i., you don't have to use most of your 'import' statements if your classes are all in the same package.

Saving customized movieclip as an image to local disk (diy generator)

dropbox.com/s/77euop1luqjreos/FINAL.fla
Ok i just gave up with this already. I cant think of any way to save the image created by a user. Its hard to explain but please check out the fla file of my work. Basically its a diy generator. The only thing missing is a save function. Ive read filereference but its always in a document class. My code is in the timeline. Please help I'm really stuck.
edit: I got a download button that is working now!! But it only saves a small part of the movieclip: Imgur
In order to create images, you need to access the pixel data of the MovieClip object. The data can be obtained by rendering a MovieClip into a BitmapData object and using this data, you can write your own encoder to convert it to any image format you’d like. Writing such encoder is not a trivial task and requires understanding of the image format algorithm, or you can use pre-written libraries. You can download the PNGEncoder and JPGEncoder , which is part of as3corelib, an open source project library.
Using the JPGEncoder, we can convert DisplayObject into ByteArray, suitable for saving into file. If using the JPGEncoder, it’ll look like this:
import com.adobe.images.JPGEncoder;
var jpgEncoder:JPGEncoder = new JPGEncoder(quality);
//remember bitmapData here is just an example (do not try to compile this code without declare this particular variable)
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
With the PNGEncoder, it’ll look like this:
import com.adobe.images.PNGEncoder;
//remember bitmapData here is just an example (do not try to compile this code without declare this particular variable)
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
Saving Into User’s Hard Drive
Using the FileReference.save() function, we can prompt the user to save the file with the following call.
var fileReference:FileReference=new FileReference();
//in case of JPGEncoder
fileReference.save(byteArray, ".jpg");
With the two combined, here’s an example how to use:
//remember to import
import flash.net.FileReference;
import com.adobe.images.JPGEncoder; //or import com.adobe.images.PNGEncoder;
import flash.utils.ByteArray;
import flash.display.BitmapData;
//where mc_canvas will be your MovieClip instance name
var bitmapData:BitmapData = new BitmapData(mc_canvas.width, mc_canvas.height);
bitmapData.draw(mc_canvas);
var jpgEncoder:JPGEncoder = new JPGEncoder(quality_slider.value);
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
//if you want to use PNGEncoder
//var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
var fileReference:FileReference = new FileReference();
fileReference.save(byteArray, ".jpg");

How to import FXG to a Shape?

I can import FXG files as Sprites as follows:
import graphics.mypic; // graphics/mypic.fxg
var mysprite:Sprite = new mypic();
I don't always need the fancy things that come with Sprites. How can I import them to Shapes?
No, you can't cast them as Shape(s) - the internal compile-time FGX is built on top of Sprite. You can find that out by running
var tig:* = new tiger();
if (tig instanceof Sprite)
...
What George Profenza is referring to is runtime loading of FXG's
I don't know if there's a better way to do this know, but last year I've played with a nice FXGParser library that simplified things a lot.
Get the library:
svn export http://www.libspark.org/svn/as3/FxgParser/
Use it:
import fxgparser.FxgDisplay;
import graphics.mypic;
var fxg:XML = new XML(mypic);//this bit depends on how you load/embed the fxg xml
var mysprite: FxgDisplay= new FxgDisplay( fxg );
addChild( mysprite );
Goodluck!

import classes? is it nesecarry?

why import classes if they work even if you don't?
import flash.display.Sprite;
import flash.events.MouseEvent;
var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFFCC00);
circle1.graphics.drawCircle(40, 40, 40);
circle1.buttonMode = true;
circle1.addEventListener(MouseEvent.CLICK, clicked);
why are we ment to import classes if the code is working anyways? if the two import lines are escaped the code will still be working
If the code is compiled as strict, it needs those imports. Unless the instances are decalred as fully qualified class names.
e.g.
var circle1:flash.display.Sprite = new flash.display.Sprite();
Which I'm sure you don't want to do ;)
I'd always recommend compiling in strict mode anyway, and making sure that your code is properly typed and has the required references (imports).