Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to Make a Basic Javascript Text Editor using DroidScript Part 1

javascript how to

  • Please log in to reply
1 reply to this topic

#1 YoungPythoner

YoungPythoner

    CC Newcomer

  • Member
  • PipPip
  • 17 posts
  • Location:Turkey, Hatay
  • Programming Language:Python, Bash, Others
  • Learning:JavaScript, Delphi/Object Pascal

Posted 02 July 2015 - 04:18 AM

HOW TO MAKE A BASIC JAVASCRIPT TEXT EDITOR USING DROIDSCRIPT:

1- Create Layouts

2- Create Objects (etc. button, textbox...) and Set On Touch

3- Add Objects To Layouts

4- Create Functions

5- Finished!

 

1-:

First, we must create layouts with "app.CreateLayout()". These layouts is shows our objects. We create two layouts. A layout for buttons with type linear horizontal (layh). A layout for layh and textbox with type linear FiilXY (lay).

lay = app.CreateLayout("linear", "FillXY")
layh = app.CreateLayout("linear", "Horizontal")

2-:

Now we create objects. A textbox and two buttons.

txtbox = app.CreateTextEdit("Write something.", 1, 0.9)
btn1 = app.CreateButton("Save", 0.3, 0.1)
btn2 = app.CreateButton("Load", 0.3, 0.1)

Now we set on touch.

btn1.SetOnTouch(save)
btn2.SetOnTouch(load)

3-:

And add objects to layout.

layh.AddChild(btn1)
layh.AddChild(btn2)
lay.AddChild(txtbox)
lay.AddChild(layh)
app.AddLayout(lay)

4-:

I write functions and other things in part 2.


  • 0

#2 YoungPythoner

YoungPythoner

    CC Newcomer

  • Member
  • PipPip
  • 17 posts
  • Location:Turkey, Hatay
  • Programming Language:Python, Bash, Others
  • Learning:JavaScript, Delphi/Object Pascal

Posted 06 July 2015 - 12:55 AM

Welcome to part 2!

Now we are typing functions.

There are two functions. Save and load.

Save:

function save()
{
filename=prompt("Write file name.")
txt=txtbox.GetText()
//Before filename there is path.
app.WriteFile(filename, txt)
}

Load:

function load()
{
filename=prompt("Write file name.")
//Before filename there is path.
txt=app.ReadFile(filename)
txtbox.SetText(txt)
}

And run! My tutorial is ended. Hope you like it!


  • 0