Flash AS3:Multiple function in one key? - actionscript-3

Etc: if I press "space" key, inventory opens.But if I press "space" again, inventory should close.What should I use for this kind of thing?I can open it, but cant close.Thanks, sorry for bad english.(P.S: Im using flashdevelop+flixel)

Yes, this is completely possible.
var isInventOpen:Boolean = false;
function openCloseInvent(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.SPACE && isInventOpen == false)
{
//Open Inventory
isInventOpen = true;
}
if(e.keyCode == Keyboard.SPACE && isInventOpen == true)
{
//Close Inventory
isInventOpen = false;
}
}
More info on KeyCodes can be found here: KeyCodes, if you need it.

You should give yourself a boolean, like so:
var menuOpen:Boolean = false;
function yourEventHandler(e:KeyboardEvent):void {
if (menuOpen) {
menuOpen = false;
//close your menu here
} else {
menuOpen = true;
//open menu here
}
}

Related

using condition in jquery onclick button

Im trying to confirm if the password strength is strong or weak and is the password is strong and when I submit it should have alert message like "You Have Strong Password" and when its weak "Invalid Password"
This is what I am now.
function checkPasswordStrength() {
var passwordStrength = false;
var number = /([0-9])/;
var alphabets = /([a-zA-Z])/;
var special_characters = /([~,!,#,#,$,%,^,&,*,-,_,+,=,?,>,<])/;
if ($('#password').val().length < 8) {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('weak-password');
$('#password-strength-status').html("Weak (should be atleast 8 characters.)");
} else {
if ($('#password').val().match(number) && $('#password').val().match(alphabets) && $('#password').val().match(special_characters)) {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('strong-password');
$('#password-strength-status').html("Strong");
return passwordStrength = true;
} else {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('medium-password');
$('#password-strength-status').html("Medium (should include alphabets, numbers and special characters.)");
}
}
}
$('#btn-submit').click(function () {
if (passwordStrength == false) {
alert("INVALID PASSWORD");
} else {
alert("You have Strong PASSWORD");
}
</script>
its for Educational Purpose only im just starting jquery..
thank you in advance..
You need to call the function instead of just checking your variable. So rather do
$('#btn-submit').click(function () {
if (checkPasswordStrength() === false) {
instead of
$('#btn-submit').click(function () {
if (passwordStrength == false) {
Then, instead of return passwordStrength = true; you should do just passwordStrength = true and add a return passwordStrength to the very end of your function so it will return either false or true.
It looks like the variable scope is incorrect. var passwordStrength should be put outside of the checkPasswordStrength function.
var passwordStrength
function checkPasswordStrength() {
....

Shortcut key(Alt+s or Alt+w etc) in html5

how to write code for shortcut key html5 like below image link.
http://screencast.com/t/iHOJqwy9
Seems a duplicate question but few possible solutions are:
How to detect Ctrl+V, Ctrl+C using JavaScript?
$(document).ready(function()
{
var ctrlDown = false;
var ctrlKey = 17, vKey = 86, cKey = 67;
$(document).keydown(function(e)
{
if (e.keyCode == ctrlKey) ctrlDown = true;
}).keyup(function(e)
{
if (e.keyCode == ctrlKey) ctrlDown = false;
});
$(".no-copy-paste").keydown(function(e)
{
if (ctrlDown && (e.keyCode == vKey || e.keyCode == cKey)) return false;
});
});
$(document).bind('keydown', 'ctrl+c', function(event){
$.fancybox.close(); // if this is commented out, CTRL-C works just fine
return true;
});
$(document).keydown(function(e) {
if (e.keyCode == 67 && e.ctrlKey) {
/* do your stuff */
$("#test").text("copied!"); /* optional */
}
});
jquery hotkeys and CTRL-C

cleaning up angularjs controller and function - for drop down list with multi select custom made

how can I clean up this code. here is my function in my controller. I am using this to control 3 different custom made drop down lists in my html. I want when you click out of them, they close. I wish I didn't need to give them each their own variable for ng-show, but I think I do because if ng-show is true for one then they would all show together. Also is it wrong to put all this in a controller rather than a directive or factory or something - besides for cleaning up the function itself.
$scope.toggle = function (option,type) {
if (option == 'subdiv') {
$scope.notMain = true;
if ($scope.notMain) {
if (type == 'item') {
$scope.showItemOptions = true;
$scope.showOptions = false;
$scope.showOrderOptions = false;
}
else if (type == 'style') {
$scope.showOptions = true;
$scope.showItemOptions = false;
$scope.showOrderOptions = false;
}
else if (type == 'order') {
$scope.showOrderOptions = true;
$scope.showItemOptions = false;
$scope.showOptions = false;
}
}
}//end of if subdiv
else if (option == 'maindiv') {
if (!$scope.notMain) {
$scope.showItemOptions = false;
$scope.showOptions = false;
$scope.showOrderOptions = false;
}
$scope.notMain = false;
}//end of if maindiv
};
here is the html for just one of the drop downs (but they are all the same with different variables:
<div class="dropdownlistheader" ng-click="toggle('subdiv','order')">
<input type="text" readonly="readonly" class="dropdownlistinput" value="{{selectedOrderValuesDisplay}}" /> </div>
<div id="ddl123" ng-show="showOrderOptions" class="dropdownlist">
<div ng-show="showOrderOptions" ng-repeat="option in OrdersDDL">
<label> <input type="checkbox" ng-model="selected[$index]" ng-click="toggleOrderSelection(option.Number, option.Details)"> {{option.Details}}</label> </div></div>
I changed the whole thing to one function. was able to do it easily by changing the ng-show variables to contain the text of of the name of the ddl that should show instead of bool like they were.
$scope.toggle = function (option,type) {
if (option == 'subdiv') {
$scope.notMain = true;
if ($scope.notMain) {
$scope.showDDL = type;
}
}
else if (option == 'maindiv') {
if (!$scope.notMain) {
$scope.showDDL = '';
}
$scope.notMain = false;
}
};
in html: ng-show=="type" //type is hardcoded in html

combo box validation

content this is the java script code.for validating combo boxes..the validation is not workin properly..i needed ur help..plz help me..if the user doesnt select it has to show an alert box for all the tree
<script type="text/javascript">
function checkseats() {
if (!document.getElementsByName("seats")[0].selectedIndex == 1) {
alert("Select No of Seats");
return false;
}
return true;
}
function checkmovie() {
if (document.getElementsByName("movie")[0].selectedIndex == 2) {
alert("Please select Movie from the list");
return false;
}
return true;
}
function checkdate() {
if (document.getElementsByName("date")[0].selectedIndex == 3) {
alert("Please select Date from the list");
return false;
}
return true;
}
function validate() {
checkdate();
checkseats();
checkmovie();
}
</script>
I think you want this instead,
if (document.forms["yourFormName"].seats.value == "0"){
alert("Select No of Seats");
return false;
}
return true;
}

Unable to use drag Drop in radtreeview

I have binded all data to RadTreeView but unable to use drag-'n-drop. I used four properties as
IsDragDropEnabled="True"
IsDropPreviewLineEnabled="True"
AllowDrop="True"
IsDragPreviewEnabled="True"
and I want to drop an item within same tree. But it doesnt work.
There is quite a bit of info here : http://www.telerik.com/help/silverlight/raddraganddrop-events.html
But I'm also having trouble with the tree view.
After a quick read of this telerik article, drag-drop seems to be working quite well for me.
<telerik:RadTreeView ... EnableDragAndDrop="true" OnNodeDrop="MyTreeView_NodeDrop">
EnableDragAndDrop and OnNodeDrop seem to be the two vital pieces to getting it working, but weren't in your list of attributes you tried. HTH
<telerik:RadTreeView x:Name="treeView1" IsDragDropEnabled="True" Margin="2,0,0,0" ItemsSource="{Binding SelectedSectionList, Mode=TwoWay}" ItemTemplate="{StaticResource SectionTemplate}" IsEditable="True" SelectedItem="{Binding SelectedCustomSectionList, Mode=TwoWay}" Grid.Column="2">
Now in the code behind
You have to fire event
In Constructor
this.treeView1.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);
Then
private void OnDropQuery(object sender, DragDropQueryEventArgs e)
{
RadTreeViewItem destinationItem = e.Options.Destination as RadTreeViewItem;
object source = this.GetItemFromPayload<object>(e.Options.Payload);
object target = destinationItem != null ? destinationItem.Item : null;
DropPosition position = destinationItem != null ? destinationItem.DropPosition : DropPosition.Inside;
if (source != null && target != null)
{
Section sourceSection = source as Section;
Section targetSection = target as Section;
Question sourceQuestion = source as Question;
Question targetQuestion = target as Question;
if (sourceQuestion != null)
{
try
{
if (sourceQuestion != null && targetQuestion != null && object.ReferenceEquals(sourceQuestion, targetQuestion))
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
if (targetQuestion != null && position == DropPosition.Inside)
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
if (position != DropPosition.Inside && targetQuestion == null)
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
}
catch (Exception ex)
{
}
}
}
else
{
e.QueryResult = false;
return;
}
e.QueryResult = true;
}
This is it. You will be able to drag and drop.