Previous Topic Tutorial Home Page Next Topic
Using DirectAnimation to Jump to another Website
import com.ms.dxmedia.*;
import java.awt.*;
import java.net.*;
gets URL.
import java.applet.*;
gets getAppletContext.

public class JumpURL extends DXMApplet {

public void init() {
super.init() ;
JumpURLModel newJump = new JumpURLModel();
setModel(newJump);


There are two main pieces to any DirectAnimation applet, the DXMApplet class and the Model class. To use the DirectAnimation classes, import the media libraries like this:
newJump.appLink(getAppletContext());
}
}

Call AppletContext() and set _getAppContext to its return. _getAppContext will be used to call showDocument().
class JumpURLModel extends Model {

public void createModel(BvrsToRun blist) {

Then create a class that extends the Model class. In this class the createModel method is where you construct your animation. This example will make use of two of the primary media types supported by DirectAnimation: images and sound.
URL mediaBase = getImportBase();
URL imgBase = buildURL(mediaBase,"image/");
URL sndBase = buildURL(mediaBase,"sound/");

Create bases for importing images and sounds.
ImageBvr seattleImg = importImage(buildURL(imgBase,"seattle.jpg"));

Import seattle.jpg.
SoundBvr pickSnd = importSound(buildURL(sndBase,
"etherial.mp2"),null).loop();

Import the sound that will be played when the mouse moves over seattleImg.
PickableImage pickPImg = new PickableImage(seattleImg,true);

Make seattleImg pickable.
DXMEvent pickEv = pickPImg.getPickEvent();

Create an event that will trigger when the mouse moves over detectImg.
ImageBvr pickImg = pickPImg.getImageBvr();

Get the image part of pickPImg.
StringBvr urlStr = toBvr("http:
seattle.sidewalk.com");

Create a string that contains the URL to Seattle Sidewalk.
FontStyleBvr font = font("Arial",12,white).bold();
ImageBvr tipTxtImg = stringImage(
"Click the red dot to go to Seattle Sidewalk", font);

Bbox2Bvr txtBB = tipTxtImg.boundingBox();

ImageBvr tipBackImg = solidColorImage(black)
.crop(txtBB.getMin(),txtBB.getMax());

ImageBvr tipImg = overlay(tipTxtImg,tipBackImg);

Create the tip box (tipImg), which consists of a black backgroud (tipBackIm), and white text (tipTxtIm).
ImageBvr jumpImg = solidColorImage(red).crop(point2(-0.003,-0.003),
point2(0.003,0.003));

jumpImg = jumpImg.transform(translate(toBvr(0),
mul(toBvr(-50),pixelBvr)));

Create a detectable image (jumpImg)and crop it to 6 by 6 mm. This image will be made pickable and used to jump to Seattle Sidewalk.
PickableImage jumpPImg = new PickableImage(jumpImg,true);

Make detectImg pickable.
DXMEvent jumpEv = jumpPImg.getPickEvent();

Create an event that will trigger when the mouse moves over jumpImg.
DXMEvent jumpClickEv = andEvent(leftButtonDown, jumpEv);

Create an event that will trigger when both the mouse moves over jumpImg, and the left mouse button is clicked.
ImageBvr jumpPointImg = jumpPImg.getImageBvr();

Get the image part of jumpPImg.
TupleBvr compTup1 = pairBvr(pickPImg.getImageBvr(),silence);
ImageBvr finalImg = overlay(jumpPointImg,overlay(tipImg,pickImg));
TupleBvr compTup2 = pairBvr(finalImg,pickSnd);

Combine the pickable images with the tip box and pair them with sound.
TupleBvr pickedTup = TupleBvr.newUninitBvr(pairBvr(emptyImage,silence));
pickedTup.init(until(compTup1,pickEv,until(compTup2,
notEvent(pickEv),pickedTup)));

Create a behavior (pickTup) that start out as a detectable empty image with no sound. When the mouse moves over it, the sound changes to pickSnd, and the tip box is displayed. When the mouse is no longer over it, it returns to the original behavior.
TupleBvr finalTup = (TupleBvr)untilNotify(pickedTup,
jumpClickEv,new JumpURLLink(urlStr));

Create a behavior that starts out as pickedTup, and that jumps to the Seattle Sidewalk site when the user clicks on pickPImg using the left mouse button.
setImage(overlay((ImageBvr)finalTup.nth(0),
overlay(seattleImg,solidColorImage(black))));

Display the final image.
setSound(mix((SoundBvr)finalTup.nth(1),silence));
}

public void appLink(AppletContext appGet) {
_getAppContext = appGet;
}
public static AppletContext _getAppContext;
}

class JumpURLLink extends Statics implements UntilNotifier {

public JumpURLLink(StringBvr url) {

Start the sound.
try {
_clickDest = new URL((String) url.extract());
}
catch(MalformedURLException mal) {
System.out.println("Malformed URL: Check Applet Tag.");
}
}

public Behavior notify(Object eventData,
Behavior currentRunningBvr, BvrsToRun btr) {

Convert urlStr into an URL.
JumpURLModel._getAppContext.showDocument(_clickDest,"_parent");

Use the Java showDocument method to load the Seattle Sidewalk page in the parent frame.
return currentRunningBvr;
}
URL _clickDest;
}
Return currentRunningBvr to keep the UntilNotify happy.

Thats all there is to it. Happy animating...

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

Previous Topic Tutorial Home Page Next Topic