Trouble getting all of the variables to work, once one is clicked - variables

just a quick question. Basicaly, I'm making a simple game to accompany my murder mystery interactive website and I'm having some actionscript issues. The idea is that the user will be able to click on objects around the room, and recieive clue, find keys etc. One of the problems im having is when the user clicks the lamp, it brings up a box over the screen to resemble nighttime, however, when the screen reverts to normal, none of the other elements, i.e the book, are clickable - again, im sure this is a simple solution that I am just overlooking, here is the full code;
import flash.events.Event;
import flash.events.MouseEvent;
book.addEventListener(MouseEvent.CLICK,getBook);
key.addEventListener(MouseEvent.CLICK,getKey);
door.addEventListener(MouseEvent.CLICK,gotoBedroom);
//paper.addEventListener(MouseEvent.CLICK,getNote);
Lamp.addEventListener(MouseEvent.CLICK,getDark);
var gotBook:Boolean = false;
var gotKey:Boolean = false;
key.visible = false;
NightTime.visible = false;
//function getNote(evt:MouseEvent):void{
//report.gotoAndPlay(1);
//}
function getKey(evt:MouseEvent):void{
if(gotBook==false){
key.visible = false;
}else{
key.visible = true;
}
}
function gotoBedroom(evt:MouseEvent):void{
if(gotKey==true){
gotoAndStop("Bedroom");
}else
feedBackText.gotoAndPlay(1);
}
if(gotBook==true){
book.visible = false;
key.visible = true;
}
function getBook(evt:MouseEvent):void{
book.visible = false;
key.visible = true;
}
function getDark(evt:MouseEvent):void{
NightTime.gotoAndPlay(1);
NightTime.visible = true;
}
stop()
any help in making all of the variables clickable at the same time would be greatly appreciated. Thank you!

If I get it right, by calling getDark function you show NightTime box (or whatever it is) which cover the screen. I can't see function which is calling
NightTime.visible = false;
so i guess after you show it it's there all the time and overlap rest of screen.
If that's the reason, adding
NightTime.mouseChildren = false;
NightTime.mouseEnabled = false;
should solve the problem.

Related

Titanium geolocation distanceFilter property is not working as expected

Need a help here for geolocation API - even after using Titanium.Geolocation.distanceFilter = 10; 10 in meter callback function is getting triggered randomly without moving here and there. Any idea what is wrong here ?
function Geolocate() {
var self = this;
// The callback function we should call when location is finally determined
this.locationReceivedCallback = function () {};
// Check if location event is already triggered or not
this.isLocationEventRegister = false;
// The function that unregisters the location event
this.unregisterLocationEvent = function () {
this.isLocationEventRegister = false;
Ti.Geolocation.removeEventListener('location', self.locationReceivedCallback);
};
}
Geolocate.prototype.init = function () {
// Setting up some preference values
Titanium.Geolocation.distanceFilter = 10; //The minimum change of position (in meters) before a 'location' event is fired.
if (deviceDetect.isIos()) {
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; // Using this value on Android enables legacy mode operation, which is not recommended.
} else {
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_LOW; //Using this value on Android enables simple mode operation.
}
};
Geolocate.prototype.getCurrentPosition = function (callback) {
this.isLocationEventRegister = true;
this.locationReceivedCallback = callback;
Titanium.Geolocation.addEventListener("location", this.locationReceivedCallback);
};
Geolocate.prototype.locationServicesAreAvailable = function () {
if (Titanium.Geolocation.locationServicesEnabled) {
return true;
} else {
return false;
}
};
Geolocate.prototype.cancelLocationRequest = function () {
this.unregisterLocationEvent();
};
module.exports = Geolocate;
Actual scenario is whenever I clicked on get location its gives me current location. then i tried to drag it map or image view for nearest place. Suddenly my view go current location. This is happening because of call back ? How to get rid off this ?
It's not a problem to do with your code, it is simply GPS in-accuracy.
GPS accuracy is (almost) never better than 10 meters, meaning it can be 10 meters off. When it recalculates your position it can be 10 meters down the line, so even if you're perfectly still with perfect GPS accuracy, you still might have differences of about 10 meters.
That said, you probably don't have best GPS accuracy when sitting behind a computer in a building, you probably have closer to 30-45 meters accuracy. Meaning every recalculation can easily be 10 meters differently.
Your solution would actually be rate-limit on top of using this property. The property will make sure it will not trigger multiple times per second, and then you can, in your own code, rate limit what you do with it.

Illustrator Script Mass PDF export bleed

im using a Savescript for a mass pdf export of multiple AI files.
The exports goes ok, except for the fact that it keeps on exporting with bleeds
(standard 3mm bleed)
this is the script: http://xcorr.net/2010/05/12/batch-export-ai-files-to-pdf/
with these saveoptios
function getPDFOptions()
{
var pdfSaveOpts = new PDFSaveOptions();
pdfSaveOpts.acrobatLayers = false;
pdfSaveOpts.colorBars = false;
pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
pdfSaveOpts.compressArt = true; //default
pdfSaveOpts.embedICCProfile = true;
pdfSaveOpts.enablePlainText = true;
pdfSaveOpts.generateThumbnails = true; // default
pdfSaveOpts.optimization = true;
pdfSaveOpts.pageInformation = false;
pdfSaveOpts.preserveEditability = false;
pdfSaveOpts.bleedLink = false;
pdfSaveOpts.bleedOffsetRect = [0,0,0,0];
pdfSaveOpts.trimMarks = false;
pdfSaveOpts.offset = 0.0;
return pdfSaveOpts;
}
i tried pdfSaveOpts.bleedLink = false; putting it on true with combination of pdfSaveOpts.bleedOffsetRect = [0,0,0,0]; but for some reason it isn't working.
Does anyone see what i'm doing wrong or have a working script?
Try setting up a pdf save preset in illustrator then specify it be used in the script with pdfSaveOpts.pDFPreset = "presetName".
You could likely skip all of the other options, no need to reinvent the wheel if it will let you use a preset. You can read about all the options you can pass here Illustrator scripting reference.
Just search for PDFSaveOptions.
The trim lines are there, they are just invisible due to the option:
pdfSaveOpts.preserveEditability = false
If you change this to true then you will see the bleeds in Illustrator again.
It's strange, but ran into this issue myself today. This is the same thing that happens when exporting directly from Illustrator, and unchecking Preserve Editability. I believe the bleeds are encoded in the file, but you just can no longer see them.

actionscript 2.0 input text box

So, here's what I'm trying to do, and I, frankly, believe it should be obvious, but I can't figure it out. I am creating a very simple Artificial Intelligence simulation. And in this simulation there's an input box at the bottom of the screen (called "input" exactly). "input" has a variable in its properties that is called "inbox" (exactly). Using a key listener the script calls up a function when the enter button is pressed. This function has 2 if statements and an else statement which dictate the responses of the AI (named "nistra"). The problem is this, When I type in what I want to say, and hit enter, it always uses the second response ("lockpick" in the code below). I have tried variations on the code but I still don't see the solution. I believe the problem is that the "typein" variable holds all the format information from the text box as well as the variable, but I could be wrong, that information is in here as well, underneath the code itself. Any help I can get would be greatly appreciated.
var typein = ""; //copies the text from inbox into here, this is what nistra responds to
var inbox = ""; //this is where the text from the input text box goes
var respond = ""; //nistra's responses go here
my_listener = new Object(); // key listener
my_listener.onKeyDown = function()
{
if(Key.isDown(13)) //enter button pressed
{
typein = inbox; // moves inbox into typein
nistraresponse(); // calles nistra's responses
}
//code = Key.getCode();
//trace ("Key pressed = " + code);
}
Key.addListener(my_listener); // key listener ends here
nistraresponse = function() // nistra's responses
{
trace(typein); // trace out what "typein" holds
if(typein = "Hello") // if you type in "Hello"
{
respond = "Hello, How are you?";
}
if(typein = "lockpick") // if you type in "lockpick"
{
respond = "Affirmative";
}
else // anything else
{
respond = "I do not understand the command, please rephrase";
}
cntxtID = setInterval(clearnistra, 5000); // calls the function that clears out nistra's response box so that her responses don't just sit there
}
clearnistra = function() // clears her respond box
{
respond = "";
clearInterval(cntxtID);
}
// "typein" traces out the following
<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Times New Roman" SIZE="20" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">test</FONT></P></TEXTFORMAT>
Since ActionScript is based on ECMAScript I'm pretty sure that you need to use == instead of = for equality comparison.
Right now your code works like this:
if(typein = "Hello") { // assign "Hello" to typein. always true.
respond = "Hello, How are you?";
}
if(typein = "lockpick") { // assign "lockpick" tot ypein. always true.
respond = "Affirmative";
}
// the else block is always false for obvious reasons
So you simply need to change the code like this:
if(typein == "Hello") {
respond = "Hello, How are you?";
}
else if(typein == "lockpick") {
respond = "Affirmative";
}
else {
respond = "I do not understand the command, please rephrase";
}

Turning Multiple Layers On and Off in Photoshop Script

I have 6 groups in Photoshop that contain a number of layers within each group. I'm looking to turn on/off a layer within each group to create every possible combination of the image.
Can someone point me in the right direction?
I've never scripted in Photoshop but trying to figure this out on my own.
I'm quite new to CS5 scripting myself, but I think I can explain how it works. The code examples may not be the most effective way to do it, but it does the trick.
There is a big difference between a Group of layers or the individual layer itself.
All layers and groups are ordered in the DOM format. To get your root you can use the global instance app to get the active document: app.activeDocument.
The messy part is that there are two separate arrays for single layers and groups.
To get the array of single layers use app.activeDocument.layers and app.activeDocument.layerSets for the groups.
To go deeper down in the hieralcy, use the layerSets array to iterate down.
For example, let us assume the following hieralcy:
-Border
+Icons
+Left
-Star
-Home
+Right
-Add
-Remove
Here Border, Star, Home, Add and Remove are all single layers while Icons, Left and Right are Groups.
To turn on group Left we need to iterate down the Icon group:
Icons = app.activeDocument.layerSets.getByName("Icons");
Left = Icons.layerSets.getByName("Left");
Left.visible = true;
If you show a layer/group in CS5 by clicking with your mouse, all parent groups will automatically be shown too. By scripting this isn't the case, you have to enable all parents as well.
Icons = app.activeDocument.layerSets.getByName("Icons");
Icons.visible = true;
Left = Icons.layerSets.getByName("Left");
Left.visible = true;
To show the Border layer you need to use the layers array instead.
app.activeDocument.layers.getByName("Border").visible = true;
Same things apply if you want to show the Add layer.
Icons = app.activeDocument.layerSets.getByName("Icons");
Icons.visible = true;
Right = Icons.layerSets.getByName("Right");
Right.visible = true;
AddLayer = Right.layers.getByName("Add");
AddLayer.visible = true;
This can be a bit messy if you have a lot of groups and layers. I created a function that follows a supplied path to get the end object. It will determine by itself if it is a layer or a group.
//******************************************
// GET BY PATH
// Author: Max Kielland
//
// Gets the LayerSet or Layer at the path's end.
// Example path "Icons/left" will return the LayerSet object "Left"
// while "Icons/left/Star" will return the Layer object "Star"
// If fSetPath is true, all the parents will be visible as well.
function GetByPath(fPath,fSetPath) {
var lGroup = null;
var lPathArray = new Array();
lPathArray = fPath.split('/');
try {
lGroup = app.activeDocument.layers.getByName(lPathArray[0]);
} catch (err) {
lGroup = app.activeDocument.layerSets.getByName(lPathArray[0]);
}
if (fSetPath)
lGroup.visible = true;
for (n=1; n<lPathArray.length; n++) {
try {
lGroup = lGroup.layerSets.getByName(lPathArray[n]);
} catch(err) {
lGroup = lGroup.layers.getByName(lPathArray[n]);
}
if (fSetPath == true)
lGroup.visible = true;
}
return lGroup;
}
...and one function to simply set or clear a group or layer by its path.
//******************************************
// SET STATUS
// Author: Max Kielland
//
// Sets the Group or Layer's visible property
// at the end of the path to fStatus.
function SetStatus(fPath, fStatus) {
Obj = GetByPath(fPath,false);
Obj.visible = fStatus;
}
..and at last I wrote this function to hide all groups and/or layers from a user specified root.
/******************************************
// CLEAR GROUP
// Author: Max Kielland
//
// Clears the visible property in a single
// group/layer with the option to clear all
// its children as well (fRecurs = true).
// fLayerSet can be a layerSet object or a
// String path.
function ClearGroup(fLayerSet,fRecurs) {
var n;
var TargetGroup;
// Get LayerSet Object if reference is a string.
if (typeof fLayerSet == "string")
TargetGroup = GetByPath(fLayerSet);
else
TargetGroup = fLayerSet;
// Iterate through all LayerSets
for (n=0; n<TargetGroup.layerSets.length; n++) {
if (fRecurs == true)
ClearGroup(TargetGroup.layerSets[n],true);
else
TargetGroup.layerSets[n].visible = false;
}
// Iterate through all layers
for (n=0; n<TargetGroup.layers.length; n++) {
TargetGroup.layers[n].visible = false;
}
// Clear self
TargetGroup.visible = false;
}
Here is an example of how to use the functions
// Hide group "Icon" and its children
ClearGroup("Icons",true);
//Show the layer "Home"
GetByPath("Icons/Left/Home",true);
// To just get the object "Right"
var MyGroup = GetByPath("Icons/Right");
// Save the current document as a PNG file
app.activeDocument.saveAs(File("Scripted Document.png"),PNGSaveOptions);
I hope this is useful to someone more than just me :)

Play and pause functions works only once

I'm viewing the live streams using the flash player. while i'm doing that i have tried to play and pause the streams using the following function but it is only works for only one click. if i'm re-clicking it does not shows any changes. If you realize my problem. please suggest me.
function testPause(event:MouseEvent) {
nsPlay.pause();
}
function testPlay(event:MouseEvent) {
if(!bolLoaded) {
nsPlay.play(streamValue);
bolLoaded = true;
} else {
nsPlay.resume();
}
}
Make Boolean variable value FALSE in pause state.
bolLoaded = false;