Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Build Scratch2.0 to upload works to local server, cover images, etc.

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "Scratch2.0 building to upload works to the local server, cover images, etc.", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Scratch2.0 building to upload works to the local server, cover images, etc."

For old machines, it may not be possible to use scratch4.0. Now, 2.0 and 3.0 co-exist. The solution allows old machines to experience scratch programming normally.

Scratch3.0 gets the address

Https://github.com/LLK/scratch-flash.git

Git command: git clone https://github.com/LLK/scratch-flash.git

Preparation in advance

Flex sdk 4.6 (download and install by yourself, configure environment variables)

Jdk 1.8 (download and install by yourself, configure environment variables)

Development tools

It is recommended to use Flash Builder (please install it yourself). IDEA has been built successfully, and you will always encounter some inexplicable problems (use and problems will be introduced later).

Benefits: import projects do not need to do other additional configuration, import can be run

1. Open flash builder

two。 File-> Import flash builder. The imported project is as follows

3. Right-click the-> property on the project, you can refer to the following configuration. The following pictures are from my real environment.

Additional compiler parameters

-locale zh_CN-swf-version=19-default-size=1024768-define+=SCRATCH::allow3d,false-define+=SCRATCH::revision,'20191022'

4. Run-> Modal configuration

Click the debug button to start the scratch3.0 program, and it can be run without accident.

Question summary

1. The problem of blank resources (the official website says that resources are copyrighted, that is, they are not open source. You can download the stand-alone version and find all the resources in the installation directory media)

1.1 New internalapi/asset, medialibraries and medialibrarythumbnails under scr

1.2 put several json files under media/libs in the stand-alone directory into the medialibraries directory

1.3 put all the pictures and audio json files in the stand-alone directory in media into the other two folders (here should be divided, too many do not want to find)

1.4 modify the src- > util- > service.as getOfficialExtensionURL method, approximately 104 lines

/ / Returns a URL for downloading the JS for an official extension given input like 'myExtension.js' public function getOfficialExtensionURL (extensionName:String): String {var path:String; if (Scratch.app.isOffline) {path =' static/js/scratch_extensions/' } else if (Scratch.app.isExtensionDevMode) {path = 'scratch_extensions/' } else {/ / Skip the CDN when debugging to make iteration easier var extensionSite:String = Capabilities.isDebugger? URLs.sitePrefix: URLs.siteCdnPrefix; path = extensionSite + URLs.staticFiles + 'js/scratch_extensions/';} path + = extensionName; return path;}

GetAsset method

Public function getAsset (md5:String, whenDone:Function): URLLoader {/ / if (BackpackPart.localAssets [md5] & & BackpackPart.localAssets[ MD5] .length > 0) {/ / whenDone (BackpackPart.localAssets[ MD5]); / / return null / /} var url:String = ""; if (Scratch.app.isOffline) {url=URLs.internalAPI+'asset/' + md5 } else {url = URLs.assetCdnPrefix + URLs.internalAPI + 'asset/' + md5 +' / get/';} return serverGet (url, whenDone);}

GetMediaLibrary method

Public function getMediaLibrary (libraryType:String, whenDone:Function): URLLoader {var url:String = ""; if (Scratch.app.isOffline) {url='medialibraries/' + libraryType + 'Library.json' } else {url=getCdnStaticSiteURL () + 'medialibraries/' + libraryType +' Library.json';} return serverGet (url, whenDone);}

SetDefaultURLs method

/ / No default URLs protected function setDefaultURLs (): void {/ * URLs.sitePrefix = "https://scratch.mit.edu/"; URLs.siteCdnPrefix =" https://cdn.scratch.mit.edu/"; URLs.assetPrefix = "https://assets.scratch.mit.edu/"; URLs.assetCdnPrefix = "https://cdn.assets.scratch.mit.edu/"; URLs.projectPrefix =" https://projects.scratch.mit.edu/"; URLs.projectCdnPrefix = "https://cdn.projects.scratch.mit.edu/";*/ URLs.internalAPI =" internalapi/ " URLs.siteAPI = "site-api/";}

All right. Just open it and have a look. You can debug it by printing logs. If something is wrong, modify it. The directory you just built can be understood as the resource directory under web.

two。 Chinese language

Create a locale directory under the 1.scr directory, but you don't need it if you don't need it. Delete it without English. Take a look at what lang_list.txt wants and keep that. Then in the stand-alone version of the zh-cn.po will be copied over, it is OK.

two。 The initialize method in Scratch.as can be modified by default Chinese when the project is started to add

Translator.setLanguageValue ('zh-cn')

3. Load default role

Make the roles you want to load into the resource package of sb, which is similar to resource loading. This method has been implemented in Scratch.as at line 306 of loadSingleGithubURL.

InitProjecteUrl = initProject/default.sb2, create a new initProject directory under the scr directory, and put it in the default.sb2 file.

4. Save the project to the local server

Modify the Scratch.as exportProjectToFile method as follows:

Public function exportUploadProjectToFile (fromJS:Boolean = false, saveCallback:Function = null): void {function squeakSoundsConverted (): void {scriptsPane.saveScripts (false); var projectType:String = extensionManager.hasExperimentalExtensions ()? '.sbx': '.sb2'; var defaultName:String = StringUtil.trim (projectName ()) DefaultName = (defaultName.length > 0)? DefaultName: 'project') + projectType; var zipData:ByteArray = projIO.encodeProjectAsZipFile (stagePane); / / var file:FileReference = new FileReference (); / / file.addEventListener (Event.COMPLETE, fileSaved) / / file.save (zipData,fixFileName (defaultName)); upLoadProjectToServer (zipData,fixFileName (defaultName)) } function fileSaved (e:Event): void {if (! fromJS) setProjectName (e.target.name) If (isExtensionDevMode) {/ / Some versions of the editor think of this as an "export" and some think of it as a "save" saveNeeded = false } if (saveCallback! = null) saveCallback ();} if (loadInProgress) return; var projIO:ProjectIO = new ProjectIO (this); projIO.convertSqueakSounds (stagePane, squeakSoundsConverted) } public function upLoadProjectToServer (data:ByteArray,fileName:String): void {var projectType:String = extensionManager.hasExperimentalExtensions ()? '.sbx': '.sb2'; if (topBarPart.fileName.text = 'Please name the work' | | topBarPart.fileName.text = =') {var CurrentDateTime:Date = new Date () FileName = "my work _" + CurrentDateTimeString () + projectType;} else {fileName = topBarPart.fileName.text+projectType;} var parameters:Object = new Object (); parameters.projectName = fileName / / get the cover image var workPic:String = stagePane.getWorkPicToBase64 (); / / ExternalInterface.call can only transmit object. Now the byteArray is converted to base64 encoding, and the js side is decoding ExternalInterface.call ("window.scratchSaveCall", Base64.encode (data), workPic,fileName);}

You can use the flex ExternalInterface.call method to call the js method in the parent window to realize the logic of uploading to the server. This method can only pass the value of the string, so you need to convert the file into base64 encoding, and the js side can convert the base64 code into a file.

5. Get the cover image

Modify the scr- > scratch- > saveScreenshot method, remove it and save it to the local method, and re-encapsulate a method. In step 4, the base64 of the image is transferred to the js side through ExternalInterface.call for processing.

/ / get the cover image public function getWorkPicToBase64 (): String {var bitmapData:BitmapData = new BitmapData (STAGEW, STAGEH, true, 0); bitmapData.draw (this); var pngData:ByteArray = PNG24Encoder.encode (bitmapData, PNGFilter.PAETH); return Base64.encode (pngData);}

Talking about the matters needing attention in the IDEA environment

When I am compiling through IDEA, the compiled swf file is not right-click, and it has not been solved yet.

In addition, the IDEA Compiler Times did not find the Sprite method, please introduce playerglobal_rb.swc. I found this in flexbuild.

Compilation parameters in moduls

Finish your work!

Below are the methods called in js. The concrete one has not been realized. This is the same as the front end. Base64 file transfer, self-baidu

Window.scratchSaveCall = (bold,picture,name) = > {console.log (bold); console.log (picture); alert ("saved successfully") If (window.worksId) {} else {}} Function save (bold) {} function updata (bold) {} Thank you for your reading The above is the content of "Scratch2.0 building to upload works to local servers, cover images, etc.". After the study of this article, I believe you have a deeper understanding of the problem of Scratch2.0 building and uploading works to local servers and cover images, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report